-
Notifications
You must be signed in to change notification settings - Fork 7.3k
http.get() raises uncatchable EBADNAME exception #1202
Comments
Originally reported here http://groups.google.com/group/nodejs/browse_thread/thread/8d23735bb6d2bae0?hl=en |
This may be related to this one: #1164 |
It seems that you're right, Dhruv. |
You're welcome :-) It would be great if you could:
Thanks! |
Yes, this is a problem... the http request is not yet attached to the connecting socket. |
Thanks a lot for the response, Ryan :) So it will be an issue resolved in future versions? I'm an using node.js for requesting multiple pages per second, and using On Mon, Jun 20, 2011 at 11:58 AM, ry <
Pedro Landeiro |
You can try using var req = http.request(blah) instead of var req = http.get(blah); And then do: This should solve your problem (at least for now). |
That was my original example, with http.request, as you can see here : http://groups.google.com/group/nodejs/browse_thread/thread/8d23735bb6d2bae0?hl=en The problem remains :( |
get() is a thin wrapper around request() so that's not surprising. |
yes, you are right. It goes through the same code path. I was hoping that the http module would create a net.Stream, attach error handlers and then try to connect(). Instead, it does a createConnection(), which doesn't give it enough time to attach the 'error' handler (or so I think). |
The DNS workaround, as posted into the Google group thread may avoid the double resolving like this: dns.lookup(opt.host, function (err, addr) {
if (err) {
// err code
} else {
// patches in the host header in order to please the HTTP/1.1 servers aka most of them
opt.headers.host = opt.host;
// makes the connection to the resolved address itself
opt.host = addr;
var req = http.request(opt);
// [...]
}
}); So far I found this to be the only reliable way around this bug. Tried the legacy interface (http.createClient()) but it doesn't support HTTPS anymore. It also lacks the abort() call. It doesn't look very elegant, but it gets the job done. |
This issue is still under investigation. Something that complicates the matter is that the test behaves differently with the legacy and libuv backends: legacy raises an uncatchable exception, libuv raises a catchable exception but doesn't seem to kill the event loop (so the script hangs). Related to |
@koichik: can you have a look at 8feb7d4 and 5fa8d0d? Solves the uncatchable exception problem in a different way by deferring the Benefit of your approach: works for both HTTP and HTTPS (mine doesn't because of how the tls module works) Applying both patches would defer the actual connection for two ticks, that seems like too much of a performance drain. Maybe we should catch exceptions and emit them as error events on the next tick? Want to talk it over on IRC? Our patches are probably two sides of the same coin. |
Does Error occur synchronously (immediately) other than DNS?
Yeah, the big difference is that my patch only invokes the callback asynchronously, whereas your patch invokes whole API (
Oops, it is too hard to me. I can write only three statements per an hour! |
net.createConnection() creates a net.Socket object and immediately calls net.Socket.connect() on it. There are no event listeners registered yet so defer the error event to the next tick. Fixes nodejs#1202.
Is there a performance problem? But if a // TCP
var addrType = binding.isIP(host);
if (addrType === 4 || addrType === 6) {
timers.active(self);
self.type = addressType == 4 ? 'tcp4' : 'tcp6';
self.fd = socket(self.type);
self.remoteAddress = host;
self.remotePort = port;
doConnect(self, port, host);
} else {
require('dns').lookup(host, function(err, ip, addressType) {
if (err) {
self.emit('error', err);
} else {
timers.active(self);
self.type = addressType == 4 ? 'tcp4' : 'tcp6';
self.fd = socket(self.type);
self.remoteAddress = ip;
self.remotePort = port;
doConnect(self, port, ip);
}
});
} |
Way too much special casing there, koichik. And it's replicating DNS logic in the TCP module, do not want. The thing I like about 60fd7e6 is that it's minimally intrusive - it fixes the bug and touches nothing else. I'm not against making DNS fully async by the way - on the contrary! - but that's something for issue #1164. |
@bnoordhuis - I have changed my mind. |
Sweet, landed in master and v0.4. |
net.createConnection() creates a net.Socket object and immediately calls net.Socket.connect() on it. There are no event listeners registered yet so defer the error event to the next tick. Fixes nodejs#1202.
Test case:
As a gist: https://gist.github.com/1033563
The text was updated successfully, but these errors were encountered: