jc-tzn jc-tzn - 1 year ago 129
Node.js Question

Nodejs Error: getaddrinfo ENOTFOUND & EADDRINFO

I'm using the Request module to fetch html pages, it works great but after some time I get errors

on some of the requests. After looking around online I found some similar issues (#699, #5488, #697) and what I understand from it is that I'm probably not consuming some (or all?) of the responses and that at some point the app reaches the socket pool max size.

I'm not really sure about all that, but I'm thinking about increasing
(to 100?) and always consuming the response by calling
at the beginning of the request callback. Does any of that make sense ? Or am I way off the tracks ?

I've looked into Node's code to try to understand what
does but I'm not sure I found the right function (#L698).

Thanks for your help.

Answer Source

Per kanaka's suggestion I'm answering my own question with the solution I found:

I did what I said I'll try and that solved the issue (not really sure why though). So before initializing the server I set http.globalAgent.maxSockets = 100 and https.globalAgent.maxSockets = 100 and every time I use the request module I add this in the callback: if (response) { response.resume(); }

Maybe that will help someone else :)