socks5-https-client icon indicating copy to clipboard operation
socks5-https-client copied to clipboard

Timeout option doesn't work + requests are stuck

Open CROSP opened this issue 8 years ago • 4 comments

Thanks for the great library, but I am dealing with the following problems.

  1. 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 ?

CROSP avatar Jun 21 '17 20:06 CROSP

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.

CROSP avatar Jun 22 '17 07:06 CROSP

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.

CROSP avatar Jun 22 '17 08:06 CROSP

same question as you. how to set timeout? It's can't work.

pscj avatar Apr 26 '19 07:04 pscj

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

oorel4 avatar Jul 03 '20 02:07 oorel4