Skip to content
Permalink
Browse files
dns: fix getServers return undefined
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 67b4edde37d84203f6a1e6e4531fe7c9ae294134
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
@@ -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];

@@ -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) => {
@@ -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.