-
Notifications
You must be signed in to change notification settings - Fork 7.3k
getaddrinfo ENOTFOUND in dns.js when doing a lot of HTTP requests #5545
Comments
I confirm this issue on node 0.10.4 |
Tested with 0.8.21 as well but the issue remains. |
So maybe it's not exactly the same issue. I was using the same script on two different servers; the one with 0.10.4 was giving this problem, the one with 0.8.21 wasn't. I just installed 0.8.21 on the server that was giving the problem, I'll update you if this solves it for me. |
I have the same issue on 0.10.4, but it happens consistently between 1,002 and 1,014 requests. Tested ~10 times. I noticed that the test above was building up a backlog of outstanding requests for me, so I slowed it down but had the same breaking point (just over 1,000 requests). This is an issue we're running into intermittently with our production code. Very happy to see it reproduced here. |
I confirm that with v 0.8.21 I'm not having that problem, while with 0.10.4 I was. |
I'm getting this issue too, since at least April! I'm currently on v0.10.3 and it isn't working. |
Upgrade, people! By the sound of it, you're hitting a bug that was fixed in v0.10.6. |
Unfortunately that didn't help. I just upgraded to 0.10.10 and I'm seeing the same issue. |
The issue still remains on node v0.10.10 and v0.8.24. |
Okay, there's two things here. One is a libuv bug that was fixed a while ago, hence my 'upgrade' comment. The other is that it sounds like you're hitting the EMFILE limit, the per-process open file descriptor limit. Libuv uses the getaddrinfo() POSIX function under the hood and it more or less returns what that function returns. Easy solution: crank up |
Cranking up ulimit -n is not really a solution. It probably just means that you are going to use way more resources and your app will run longer before experiencing the same issue. This bug comes about by spawning requests faster than they are actually completed. It almost seems like when you do this, even if you stop spawning new ones, the old ones don't get cleaned up correctly. I could be wrong there, though. If you want to spawn a request, and have that request spawn a new one once it is complete, there doesn't seem to be a reliable way to do it. I could not find an event that was fired after the response has been completely received and the socket has been closed. In my case, I don't actually need the response body, so as soon as I know that the response has started to be received, I just manually destroy the socket, then spawn a new request. Does that help? |
If you're referring to the test case posted above, it emits So far I'm not convinced there's a bug in node.js. I'm closing the issue unless someone convinces me otherwise. |
Ok, now I understand. The proper way would be to set var http = require('http');
var count = 0;
var options = {
hostname: 'www.google.com',
port: 80,
path: '/index.html',
method: 'GET',
agent: false
};
var makeRequest = function() {
var req;
req = http.get(options, function(res) {
count++;
console.log('STATUS: ' + res.statusCode);
console.log('Request count = ' + count);
});
req.on('error', function(e) {
console.log('problem with request: ' + e.message);
console.log('Last successful request count = ' + count);
});
};
setInterval(makeRequest, 10); |
I believe this is still an issue. Here's my reproduction case, based off the one above: I've upgraded to node v0.10.11. I still get "getaddrinfo ENOTFOUND" every time after ~1,000 http responses. |
@jdurack You're not consuming the requests that you're receiving. From http://nodejs.org/docs/latest/api/http.html#http_class_http_clientrequest:
Since the data is never consumed, the fd is never read or destroyed, so it's never closed. See the fix in my fork of your gist: https://gist.github.com/isaacs/5785971 |
I have the same issue with node v0.10.12 events.js:72 throw er; // Unhandled 'error' event ^ Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16) error: Forever detected script exited with code: 8 error: Forever restarting script for 2 time The most strange thing is that all of my code (and every callback) is turned into try-catch. In some cases exception catched, but in some (as in log above) exception not catched and application crashes. |
I've done some additional tests. 479,491,512,570,1169,1184,1291,1411,1478,1514,1596,1605,1645,1663,1712,1733,1824,1842,1929,1948,1952,2172,2185,2288,2333,2404,2413,2445,2450,2473,2488,2513,2550,2563,2571,2690,2693,2718,2835,2847,2927,3110,3156,3160,3227,3231,3389,3413,3419,3490,3524,2690,2693,2718,2835,2847,2927,3110,3156,3160,3227,3231,3389,3413,3419,3490,3524 So, I can summarize that request params are good and max file descriptors count is not exeeded. |
As workaround I added manual try-catched dns.resolve4 call before http.request. dns.resolve4(url.parse(full_url).hostname, function(e, addresses) {
if (e) {
console.log(new Date().toISOString(), url.parse(full_url).hostname, '\n', e.stack, '\n');
dns.resolve4(url.parse(full_url).hostname, function(e, addresses) {
if (e) {
console.log(new Date().toISOString(), url.parse(full_url).hostname, '\n', e.stack, '\n');
throw e;
} else {
tryDownload.apply(this,[addresses[0]]);
}
});
} else {
tryDownload.apply(this,[addresses[0]]);
}
});
var tryDownload = function(address) {
// http.request with address here
}; Now I use |
@IIIEII, your workaround worked for me |
In our case this was happening when we reached about 1000 sockets and 1024 file descriptors in total in Ubuntu. We had increased the |
this error came up when we changed the host name through code and restarted the node service.We figured out that we are not updating /etc/hosts. so dns resolution was not happening. |
What is the final conclusion on this?
This happens when I am load testing the app with just 10 requests per second |
Please see #5545 (comment). You're using a pretty old version of Node. Try upgrading and see if your problem goes away. |
This is the same issue as Issue #5488 but has a code example to reproduce.
On node v0.10.7 (on OS X 10.8.3) the error occurs for me after 240 request (on node v0.8 after 244 requests).
If
http.request
is used instead ofhttp.get
the error does not occur. Browsing through the source of nodejs I cannot find an obvious reason why.There is some more code examples in a gist I created:
https://gist.github.com/eelcocramer/5626801
The gist has 3 files:
error-case.js = script that results in the error for me after 240 requests
success-case.js = different approach to the same functionality but this does not result in the error
fixed-error-case.js = basically the same script as error-case.js but has the req.socket.close call (in line 12) as suggested by @brianseeders in Issue #5488.
The text was updated successfully, but these errors were encountered: