-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Socket connection timeouts don't fire #1523
Comments
It was like this because it was using I cannot reproduce with the steps you listed above. Here is my test case: 'use strict';
const WebSocket = require('ws');
const start = Date.now();
// Use a non-routable IP address so the connection is never established.
const ws = new WebSocket('ws://192.0.2.1', {
handshakeTimeout: 5000
});
ws.on('error', function(error) {
const elapsed = Date.now() - start;
console.log('Socket closed after %dms', elapsed);
console.error(error);
}); which prints
The issue with tls has been fixed in nodejs/node#25517, released with Node.js 11.8.0 (hopefully it will be backported). |
After I upgraded the ws to 6.1.4, it works as expected. |
I'm closing this, discussion can continue if needed. |
Timeout not functioning for ws 6.2.1 on node v8.11.4. No mention in the thread that node upgrade was requirement to fix ? |
issue.
Description
Setting a handshake timeout for a connection doesn't work if the socket never connects.
I want my app to fail fast if it can't connect to an endpoint, but I found that if I set a handshakeTimeout of 5 seconds and configured my app to talk to a known machine but on a port that just silently drops connecting packets, then it didn't time out in 5 seconds but instead would get a global ETIMEDOUT error.
Looking at the code for websocket.js it does this:
but I note that the advice for this is to wait for a socket to be assigned before setting a timeout handler. Testing this myself, I also found that just waiting for a socket wasn't enough to get the https library to handle the timeout properly, I had to also set an empty socket timeout handler on the socket itself.
So if I rewrite the code above as:
(bearing in mind you appear to have made the req var local between my version and HEAD) then I get successful 5 second timeout errors from websockets.
If you like I can make a PR for the change, I just want to make sure it's not some platform dependent issue or other strange workaround.
Thanks!
Reproducible in:
Steps to reproduce:
Create a Websockets instance connecting to a known machine and port that drops packets
Set a handshakeTimeout of 5 seconds
Set a timeout handler and see that it does not time out in 5 seconds but instead waits the minute or two for the global error handler to fire.
Expected result:
Timeout handler to fire
Actual result:
no timeout fired
Attachments:
The text was updated successfully, but these errors were encountered: