Skip to content

Commit

Permalink
dns: call handle.setServers() with a valid array
Browse files Browse the repository at this point in the history
`handle.setServers()` takes an array, not a string.

PR-URL: #50811
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
  • Loading branch information
lpinca authored and targos committed Nov 23, 2023
1 parent cc5e790 commit e8fc3d4
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/internal/dns/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const {
ArrayPrototypeForEach,
ArrayPrototypeJoin,
ArrayPrototypeMap,
ArrayPrototypePush,
FunctionPrototypeBind,
Expand Down Expand Up @@ -143,12 +142,15 @@ class ResolverBase {
}

[kSetServersInteral](newSet, servers) {
const orig = this._handle.getServers() || [];
const orig = ArrayPrototypeMap(this._handle.getServers() || [], (val) => {
val.unshift(isIP(val[0]));
return val;
});
const errorNumber = this._handle.setServers(newSet);

if (errorNumber !== 0) {
// Reset the servers to the old servers, because ares probably unset them.
this._handle.setServers(ArrayPrototypeJoin(orig, ','));
this._handle.setServers(orig);
const { strerror } = lazyBinding();
const err = strerror(errorNumber);
throw new ERR_DNS_SET_SERVERS_FAILED(err, servers);
Expand Down

0 comments on commit e8fc3d4

Please sign in to comment.