Node https ECONRESET request after 5 minutes

I am trying to make an https request to a server that takes more than 5 minutes to respond. ~ 7 minutes before sending any data over the socket and about 11 minutes for the request to complete. The request works fine when using Curl, but when making the request using node.js I get this error:

Error:  { Error: read ECONNRESET
    at exports._errnoException (util.js:1026:11)
    at TLSWrap.onread (net.js:564:26) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }

      

Code used for request:

const https = require('https');

https.get({
    hostname: 'xxx',
    path: 'xxx',
    auth: 'xxx'
  },
  (res) => {
    res.on('data', (d) => {
      process.stdout.write(d);
    });
  }).on('error', (e) => {
  console.error(e);
});

      

Since the request fails after exactly 5 minutes (300 seconds), I assume there is some kind of timeout, but I can't figure out which one or where it is. It might also be a server side timeout, but it's strange that it works with Curl ..

+3


source to share


2 answers


The solution was to use TCP Keep-Alive. https://nodejs.org/api/net.html#net_socket_setkeepalive_enable_initialdelay

req.on('socket', (s) => {
  s.setKeepAlive(true, 240000);
});

      



This will send TCP ACK packets to the socket every 4 minutes, which would be enough to solve my problem.

+3


source


From Node js ECONNRESET ,

ECONNRESET means that the other side of the TCP abruptly closed the end of the connection.

From Which parameter causes the curl to reconnect indefinitely? ,

curl will try to reconnect every time the requested operation expires.



It is defined as:

I mean using libcurl as a third party software package

Hope it helps.

0


source







All Articles