aacerox / node-rest-client

REST API client from node.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

requestConfig set timeout not work

opened this issue · comments

Please help me to review the config of requestConfig.

                  let args = {
                        headers: { 'Content-Type': 'application/json' },
                        data: {
                            
                            'data': dataUpdate
                        },
                        requestConfig: {
                            timeout: 200, // 200mili second Request timeout
                        },
                        responseConfig: {
                            timeout: 200 // 200mili second Response timeout
                        }
                    };

Seem the function set timeout not work?
When I debug , it's go to break point at function " request.on('error', function (err) " and throw error

request error { Error: connect ETIMEDOUT 54.206.64.112:8001
    at Object._errnoException (util.js:1031:13)
    at _exceptionWithHostPort (util.js:1052:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1195:14)
  errno: 'ETIMEDOUT',
  code: 'ETIMEDOUT',
  syscall: 'connect',

not go to break point of function "request.on('requestTimeout')"

public handleError(request: any, reject: any) {
       request.on('requestTimeout', function (req) {
           console.log('request has expired');
           req.abort();
       });
       request.on('responseTimeout', function (res) {
           console.log('response has expired');

       });

       request.on('error', function (err) {
           reject(err);
           console.log('request error', err);
       });
   }

do we have any support to maintain this library?

Hi. In my app, the requestConfig works well. I use ver 3.1.0.

The requestConfig.timeout seems to the timeout value from the time to send the request to the time to get the response header. If your target server is down, you get error event of ETIMEDOUT.

You can test the requestConfig.timeout by using nock. Nock can delay the response header by using delay method.

https://github.com/nock/nock#delay-the-response

Hello,

I also have this issue. But only on Windows ! If you set a timeout of e.g. 2 sec, it will never honour this timeout. It will always fail around 20 sec. and not within the 2 sec.
I also think that this has to do with some issues of the (old) request libs in node, I also have read some problems with this timeout issues...

Is there any work/maintenance on this node-rest-client ? or is it a dead project ?