node/test/parallel/test-dns-setserver-when-querying.js
XadillaX 35887306f1
dns: fix crash while setting server during query
Fix this issue follow these two points:

1. Keep track of how many queries are currently open. If `setServers()`
   is called while there are open queries, error out.
2. For `Resolver` instances, use option 1. For dns.setServers(), just
   create a fresh new default channel every time it is called, and then
   set its servers list.

Fixes: https://github.com/nodejs/node/issues/14734
PR-URL: https://github.com/nodejs/node/pull/14891
Backport-PR-URL: https://github.com/nodejs/node/pull/17778
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2018-02-19 03:18:12 +00:00

31 lines
561 B
JavaScript

'use strict';
const common = require('../common');
const dns = require('dns');
const goog = [
'8.8.8.8',
'8.8.4.4',
];
{
// Fix https://github.com/nodejs/node/issues/14734
{
const resolver = new dns.Resolver();
resolver.resolve('localhost', common.mustCall());
common.expectsError(resolver.setServers.bind(resolver, goog), {
message: /^c-ares failed to set servers: "There are pending queries\." \[.+\]$/g
});
}
{
dns.resolve('localhost', common.mustCall());
// should not throw
dns.setServers(goog);
}
}