Skip to content
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

Can't close connection in CONNECTING readyState #371

Open
nazar-pc opened this issue Sep 22, 2019 · 0 comments
Open

Can't close connection in CONNECTING readyState #371

nazar-pc opened this issue Sep 22, 2019 · 0 comments

Comments

@nazar-pc
Copy link
Contributor

I have an issue with graceful connections closing, under certain circumstances connection is not closed properly.
I blame this code:

case CONNECTING:
// NOTE: We don't have the WebSocketConnection instance yet so no
// way to close the TCP connection.
// Artificially invoke the onConnectFailed event.
onConnectFailed.call(this);
// And close if it connects after a while.
this._client.on('connect', function(connection) {
if (code) {
connection.close(code, reason);
} else {
connection.close();
}
});
break;

Essentially, if we have connection in connection.readyState === CONNECTING, we are waiting for connection to be established, but this will not happen if server is dead for instance.

I had to do this dirty workaround to handle this situation, but I believe something similar should be done in the library itself:

connection._client._req.socket.destroy()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant