-
Notifications
You must be signed in to change notification settings - Fork 7.3k
dns.setServers() crash #9243
Comments
I have the same problem with latest versions of node and iojs. |
Indeed I've confirmed this, we'll need to get this fixed. |
Why do you need the line 102 in |
@BastienLQ assertions are usually put there for a reason, and while just removing it might fix the crash, the whole library could be in an undefined state, which is very bad. |
Looking it over, I'm not sure it's an actual bug. In cares, ares-send.c invokes the callback before cleaning up. That assert appears to be designed to catch the fact that things might still be in flight when the attempt to change the servers is called. Test this: var dns = require('dns');
dns.resolveSoa('jasnell.me', function(err, soa){});
dns.setServers(['0.0.0.0']); Then this: var dns = require('dns');
dns.resolveSoa('jasnell.me', function(err, soa){});
setTimeout(
function() {
dns.setServers(['0.0.0.0']);
}, 5 * 1000
); In other words, if we delay the dns.setServers call to give cares time to complete it's cleanup, things work. Otherwise, assertion failure. |
It is a bug because |
@BastienLQ +1... I'll monitor @indutny's progress but will look at this myself again once I'm not in conference hell. (and when I say it's not a bug, I meant it in the sense that the code is working as it was written... it just wasn't written with this particular case in mind ;-) ... isn't async programming fun?) |
@jasnell the idea that I have in mind is to create new cares channel on servers change. Just didn't get time to actually implement it. |
The bug is whether or not we should be tracking outstanding requests to c-ares, and then letting them drain before calling Draining requests before setting the server will probably come with too many latency problems. The question I would have is if we destroy the existing channel and any of its outstanding requests, or if we maintain a list of active channels. Destroying the existing channel should have the effect of canceling outstanding requests, do those outstanding requests receive something of an Maintaining a list of active channels seems ideal, in that environment making sure we're doing appropriate reference counting will be crucial. We should probably document the anti-pattern of: function oneOff(server, query) {
oldServers = dns.getServers();
dns.setServers(server);
dns.resolve(query, function cb() {
dns.setServers(oldServers);
});
} Is probably not what people want, and instead should be looking to leverage an API that allows for queries to be associated with a specific request. Something like what I've done for the native-dns. |
@indutny creating the new channel on setServers sounds like a good approach. Once the old channel drains it falls off and get's de-ref'd. This allows us to keep from having to cancel inflight requests. Even so, as @tjfontaine indicates, it's an antipattern that folks should avoid. I'll see if I can get to this later this week but please cc me if you get to it first. |
It looks setServers sets the Something like: We have an server app in a docker environment with the custom DNS server deployed. Some DNS-requests should be issued against our private DNS server. And it looks the global state makes to issue this request difficult... |
@gchudnov indeed, that's not easily achieved with |
Just to track some of the progress that has been made on this, @emotional-engineering has worked on some changes and their integration into io.js plus some tests. EDIT: I have tested these changes in node v0.12 and they fix the crash mentioned in the original comment of this issue. I'm not familiar enough to review the changes themselves, but they seem to be heading in the right direction to solve the original issue ( @emotional-engineering You mentioned that the changes have been sent to the c-ares mailing list but looking at the c-ares mailing list archives, I don't see any message related to that. Did I miss something? Thank you! |
@misterdjules Yes, I missed to complete verification my email in mailing list, thank you. |
@emotional-engineering Thank you! Moving to 0.12.4, as I don't think we'll have time to come up with a robust solution before that. |
What is remaining for this issue? I'd love to help if there is remaining work but that is a little unclear based on the discussion above. |
I'm not sure we'll ever see an upstream fix for this in c-ares in a reasonable time frame. The best bet on this whole DNS business is nodejs/node#1843, which has stalled a bit unfortunately, but if you have feedback or can review the code, that'd help! |
This is reported to the current repo as nodejs/node#894, no reason to keep it open in two places. |
Hi,
In a Vagrant Ubuntu environment, node crashes with this code:
Expected result:
Actual result:
Other informations:
DNS test (in
test/simple/test-dns.js
) ends successfully.The text was updated successfully, but these errors were encountered: