In request docs parameters , scrolling down to the timeout entry:
timeout Millisecond integer to wait for the server to send the response headers (and start the response body) before interrupting the request. Please note that if the underlying TCP connection cannot be established, the connection timeout throughout the OS will override the timeout parameter (by default, Linux can take from 20 to 120 seconds).
Pay attention to the last part "if the base TCP connection cannot be established, the default connection timeout for the entire system will override the timeout parameter."
There is also a whole Timeouts section. Based on this, and your sample code, we can change the sample request as such
request(options, function(e, r, body) { if (e.code === 'ETIMEDOUT' && e.connect === true){
If so, you will need to decide if a change and acceptability of the OS parameters is possible (this is beyond the scope of this answer, and such a question would be better if the server crashes).
Matthew Bakaitis
source share