From 089b24e2b9ad80cc079a81b2bc206de5178e36d7 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Mon, 14 Aug 2017 18:12:30 +0200 Subject: [PATCH 1/2] deps: cherry-pick 0ef4a0c64b6 from c-ares upstream Original commit message: gethostbyaddr: fail with `ECANCELLED` for `ares_cancel()` When `ares_cancel()` was invoked, `ares_gethostbyaddr()` queries would fail with `ENOTFOUND` instead of `ECANCELLED`. It seems appropriate to treat `ares_cancel()` like `ares_destroy()`, but I would appreciate review of the correctness of this change. Ref: https://github.com/nodejs/node/issues/14814 Fixes: https://github.com/nodejs/node/issues/14814 --- deps/cares/src/ares_gethostbyaddr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/cares/src/ares_gethostbyaddr.c b/deps/cares/src/ares_gethostbyaddr.c index 9258919a385699..a0a90f6bb1712b 100644 --- a/deps/cares/src/ares_gethostbyaddr.c +++ b/deps/cares/src/ares_gethostbyaddr.c @@ -157,7 +157,7 @@ static void addr_callback(void *arg, int status, int timeouts, } end_aquery(aquery, status, host); } - else if (status == ARES_EDESTRUCTION) + else if (status == ARES_EDESTRUCTION || status == ARES_ECANCELLED) end_aquery(aquery, status, NULL); else next_lookup(aquery); From 32c5a6360936c84204a5f592e6b282e3b4dc3d5d Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Fri, 25 Aug 2017 00:30:53 +0200 Subject: [PATCH 2/2] test: add regression test for 14814 Ref: https://github.com/nodejs/node/issues/14814 --- .../test-dns-cancel-reverse-lookup.js | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/parallel/test-dns-cancel-reverse-lookup.js diff --git a/test/parallel/test-dns-cancel-reverse-lookup.js b/test/parallel/test-dns-cancel-reverse-lookup.js new file mode 100644 index 00000000000000..0918178e1257ba --- /dev/null +++ b/test/parallel/test-dns-cancel-reverse-lookup.js @@ -0,0 +1,29 @@ +'use strict'; +const common = require('../common'); +const dnstools = require('../common/dns'); +const { Resolver } = require('dns'); +const assert = require('assert'); +const dgram = require('dgram'); + +const server = dgram.createSocket('udp4'); +const resolver = new Resolver(); + +server.bind(0, common.mustCall(() => { + resolver.setServers([`127.0.0.1:${server.address().port}`]); + resolver.reverse('123.45.67.89', common.mustCall((err, res) => { + assert.strictEqual(err.code, 'ECANCELLED'); + assert.strictEqual(err.errno, 'ECANCELLED'); + assert.strictEqual(err.syscall, 'getHostByAddr'); + assert.strictEqual(err.hostname, '123.45.67.89'); + server.close(); + })); +})); + +server.on('message', common.mustCall((msg, { address, port }) => { + const parsed = dnstools.parseDNSPacket(msg); + const domain = parsed.questions[0].domain; + assert.strictEqual(domain, '89.67.45.123.in-addr.arpa'); + + // Do not send a reply. + resolver.cancel(); +}));