-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
net.createConnection does not have a connection timeout. #39256
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Comments
I'm not sure what you're asking for. |
I found there are some way to it like this:
but is that possible to support it natively? like this:
|
Timeout that is set during connection will work as it should. const sock = require('net').connect(123, 'google.com');
sock.setTimeout(5000); sock.on('timeout', ()=>{console.log('timeout');}); prints
(Windows has built-in 20 sec connect timeout).
So what's the problem? If you want error on timeout, /** Error code of timeout error */
const ETIMEDOUT = 'ETIMEDOUT';
/**
Create and return Error object signaling connect or idle timeout
@param {Boolean} connecting - if `true`, error is in connect stage. If `false`, error is in idle stage
@param {String} addr - host:port or IPC path
@returns {Error}
*/
function createETIMEDOUT(connecting, addr)
{
const STAGE = { false: 'idle', true: 'connect' };
const result = new Error(`${STAGE[connecting]} ${ETIMEDOUT} ${addr}`);
result.errno = ETIMEDOUT;
result.code = ETIMEDOUT;
result.syscall = STAGE[connecting];
result.address = addr;
return result;
}
sock.on('timeout', ()=>throw createETIMEDOUT(sock.connecting, addr)); |
I was trying to troubleshoot some TCP connect issue that the TCP server doesn't reply a
ACK
orRST
.So I write a simple test code to connect a port which doesn't have any service.
Normally, it will return an
ECONNREFUSED
error which is expected (because TCP will recevie aRST
packet). Like this:I'm trying to represent the situation that a TCP server doesn't reply a
RST
.So I changed the iptables rules, like this:
and run the code again:
timeout
event was emitted in 1000ms as expected, buterror
event was emitted in 132620ms.and here is the tcpdump logs:
So basically, there is no way to separate connection timeout and the socket timeout.
Ref: #5757
The text was updated successfully, but these errors were encountered: