Skip to content

Commit

Permalink
dns: fix getServers return undefined
Browse files Browse the repository at this point in the history
PR-URL: #43922
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
  • Loading branch information
jiahao-si authored and danielleadams committed Jul 26, 2022
1 parent 7c75539 commit 67b4edd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Resolver {
}

getServers() {
return ArrayPrototypeMap(this._handle.getServers(), (val) => {
return ArrayPrototypeMap(this._handle.getServers() || [], (val) => {
if (!val[1] || val[1] === IANA_DNS_PORT)
return val[0];

Expand All @@ -76,7 +76,7 @@ class Resolver {
// Cache the original servers because in the event of an error while
// setting the servers, c-ares won't have any servers available for
// resolution.
const orig = this._handle.getServers();
const orig = this._handle.getServers() || [];
const newSet = [];

ArrayPrototypeForEach(servers, (serv, index) => {
Expand Down
11 changes: 11 additions & 0 deletions test/parallel/test-dns-get-server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';
const common = require('../common');
const assert = require('assert');

const { Resolver } = require('dns');

const resolver = new Resolver();
assert(resolver.getServers().length > 0);
// return undefined
resolver._handle.getServers = common.mustCall(() => {});
assert.strictEqual(resolver.getServers().length, 0);

0 comments on commit 67b4edd

Please sign in to comment.