Timeout option doesn't work + requests are stuck
Thanks for the great library, but I am dealing with the following problems.
- When I try to set
timeout, like that
let proxyRequest = request({
url: "checkipsite",
strictSSL: true,
timeout: 2000,
resolveWithFullResponse: true,
agentClass: socks5HttpsAgent,
agentOptions: proxyCredentials
}, function (err, res) {
proxyRequest = null;
if (err) {
resolve(false);
}
else {
let ipAddress = // parse ip:
console.log(ipAddress);
resolve(ipAddress && ipAddress !== publicIp);
}
});
// TODO possible memory leak, fix timeout in request
setTimeout(function () {
if (proxyRequest !== null) {
proxyRequest.abort();
resolve(false);
}
}, REQUEST_TIMEOUT);
Here I am trying to verify whether a proxy server is alive and works. The timeout option is not considered at all, so it waits for a long time before error is thrown. 2. But all this is only one problem. The main problem is that if proxy is not working, invalid credentials or something else, this request stick in the waiting state until time is out. So I have tried to check it manually. It cancels the request, but all subsequent requests are also stuck in the waiting state even if the proxy server is valid.
I am not sure if this problem is related to this library, but it seems like first provided options are used for all subsequent request.
Could you help to solve this problem ?
I have tried to debug and got into the Socket source file, tried to use something like that socket.setTimeout(200, socket.destroy); but this doesn't work as well.
In case of the code provided above, calling abort doesn't really terminates a connection, all subsequent requests are still waiting in exactly the same way as the first connection.
I've tried to set break point at the line if (msecs === 0) {
In this function.
Socket.prototype.setTimeout = function(msecs, callback) {
if (msecs === 0) {
timers.unenroll(this);
if (callback) {
this.removeListener('timeout', callback);
}
} else {
timers.enroll(this, msecs);
timers._unrefActive(this);
if (callback) {
this.once('timeout', callback);
}
}
return this;
};
So I was able to debug all requests in my application, but didn't catch any value equal the set in my call (in that case it was 6000).
What could be wrong ? Furthermore, it seems to use connections from pool, but as far connection is stuck, it won't continue until time is out and I guess it is 30 seconds.
same question as you. how to set timeout? It's can't work.
Hello, if somebody else meets this problem. I've made some solution, some of requests still stuck, but not that much. https://github.com/oorel4/socks5-https-client-timeout https://github.com/oorel4/socks5-client-timeout https://github.com/oorel4/socks5-http-client-timeout