fix: wrap cached returns for dns lookups in nextTick

This commit is contained in:
Julian Lam
2025-06-04 13:19:29 -04:00
parent ea91dc00cd
commit 010113a9a0

View File

@@ -58,12 +58,15 @@ function lookup(hostname, options, callback) {
return; return;
} }
// Lookup needs to behave asynchronously — https://github.com/nodejs/node/issues/28664
process.nextTick(() => {
if (options.all === true) { if (options.all === true) {
callback(null, lookup); callback(null, lookup);
} else { } else {
const { address, family } = lookup.shift(); const { address, family } = lookup.shift();
callback(null, address, family); callback(null, address, family);
} }
});
} }
// Initialize fetch - somewhat hacky, but it's required for globalDispatcher to be available // Initialize fetch - somewhat hacky, but it's required for globalDispatcher to be available