-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebSocket was closed before the connection was established #183
Comments
I have exactly the same behaviour |
same issue i am also facing. |
Also has the problem. Edited the connect timeout hides the problem, but it is not a solution, since it would crash then too. Would be great if the event would be handled. |
After inspecting the code, I'm honestly not sure why the error isn't handled but I've found a decent workaround for my use case. I'm expecting that a WS endpoint might be down, so I need a way to gracefully time it out and keep retrying. using This PR should give us the ability to pass in options, but until then: import ReconnectingWebSocket from 'reconnecting-websocket';
import { type Options, type UrlProvider } from 'reconnecting-websocket';
import WebSocket, { type ClientOptions } from 'ws';
const wsFactory = (options: ClientOptions) =>
class WsOptions extends WebSocket {
constructor(url: string, protocols?: string | string[]) {
super(url, protocols, options);
}
};
export class KeepAliveWs extends ReconnectingWebSocket {
constructor(
url: UrlProvider,
protocols?: string | string[],
options: Options = {},
) {
const { connectionTimeout = 4000 } = options;
const opts = {
...options,
connectionTimeout: connectionTimeout + 1000, // give WS time to disconnect without throwing
WebSocket: wsFactory({ handshakeTimeout: connectionTimeout }),
};
super(url, protocols, opts);
}
} |
Hi, I have the same problem with ws.reconnect() function, when Iam getting:
I tried to update the code based on https://github.com/pladaria/reconnecting-websocket/pull/193, but error remain the same. My WS options are:
Also I noticed it happened when i receive close event:
Versions used:
Adding more from the logs:
Any thoughts? |
reconnecting-websocket throws unhandled error when close pladaria/reconnecting-websocket#183
This error happens when it tries to reconnect. How can I solve it?
The text was updated successfully, but these errors were encountered: