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 <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Marco Ippolito <[email protected]>
  • Loading branch information
lpinca authored and RafaelGSS committed Nov 29, 2023
1 parent d2c0dfb commit 6dfe102
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 6dfe102

Please sign in to comment.