Node.js app begins timing out (ETIMEDOUT) when HTTP connecting to other sites after having been running for some time

I connect to other websites in my node.js app using the request module in a very standard manner:

Network.prototype.httpRequest = function(url, method, params, headers, callback)
{
    var qs = typeof params === 'string' ? params : querystring.stringify(params || {}),
        config = {
            'method': (method || 'get').toUpperCase(),
            'url': url,
            'timeout': this.app.api.settings.http.timeout_outbound
        };
    if(config.method === 'GET')
    {
        config.url += '?' + qs;
    }
    else
    {
        config.body = qs;
    }

    request(config, callback);
};

After a few hours of my app being alive, this function begins timing out — and not just to one website. It begins to fail to connect (ETIMEDOUT) randomly, without any discernable pattern.

  • Difference between app.use('*') and app.all('*') in Express
  • TypeOrm - How to use connection as standalone object with types?
  • how to use sessions in express, couchDB, and node.js
  • Cannot get my Upstart script to run Node.js and Forever when server restarts
  • NPM installation issues on Mac OS Mavericks
  • How do I determine the current operating system with Node.js
  • My first, obvious guess is that something must be somehow blocking/interfering with the network connections. There are plenty of other “moving parts” in my app (eg, connecting to Mongo via Mongoose, connecting to ElasticSearch via Elastical, etc.), so it is perhaps conceivable that one of them is the cause… but obviously, it’s not really an option sit around selectively disabling other modules and waiting 6 hours to see if the problem goes away…

    I’m monitoring network traffic (via iStatMenus pro on OSX, FWIW) and do not see any unusual / persistent traffic coming from node.

    Is there any other way to delve into what might be blocking / interfering with my traffic?

  • Node.js tcp socket server on multiple machines
  • Add node module to ember CLI app
  • Amazon Elastic load balancer is not populating x-forwarded-proto header
  • Nodejs: iterate over req.files properties
  • Node.js not found
  • Node.js Configure Error: no acceptable C compiler
  • One Solution collect form web for “Node.js app begins timing out (ETIMEDOUT) when HTTP connecting to other sites after having been running for some time”

    Have you tried setting keep-alive to true? It sounds like the connection is timing out (because you’ve explicitly set a timeout) when no data is received. I ran into a similar problem while creating a socket server/client solution and this was the fix.

    (also, I may have misunderstood the question)

    Node.js is the Best Javascript runtime in the world.