Version
20.16.0
Platform
Microsoft Windows NT 10.0.22621.0
x64
Subsystem
No response
What steps will reproduce the bug?
const dns = require('dns');
const https = require('https');
// Custom DNS resolution for github.com
const customDNSLookup = (hostname, options, callback) => {
if (hostname === 'github.com') {
// Using one of GitHub's IPs as an example
return callback(null, '20.205.243.166', 4);
} else {
return dns.lookup(hostname, options, callback);
}
};
// Make a test request using native https
async function testConnection() {
const options = {
hostname: 'github.com',
path: '/',
method: 'GET',
headers: {
'Host': 'github.com'
},
agent: new https.Agent({
rejectUnauthorized: false,
lookup: customDNSLookup
})
};
return new Promise((resolve, reject) => {
const req = https.request(options, (res) => {
console.log('Successfully connected to GitHub');
console.log('Using IP:', '20.205.243.166');
console.log('Status:', res.statusCode);
resolve(res);
});
req.on('error', (error) => {
console.error('Error:', error.message);
reject(error);
});
req.end();
});
}
testConnection();
Just run this node repro.js
How often does it reproduce? Is there a required condition?
You can repro it on node v20+ it works on node v18
What is the expected behavior? Why is that the expected behavior?
Successfully connected to GitHub
Using IP: 20.205.243.166
Status: 200
This is the expected behavior because we have defined a custom lookup method to resolve to this IP
What do you see instead?
Error: Invalid IP address: undefined
node:internal/process/promises:391
triggerUncaughtException(err, true /* fromPromise */);
^
TypeError [ERR_INVALID_IP_ADDRESS]: Invalid IP address: undefined
at emitLookup (node:net:1465:17)
at customDNSLookup (C:\Aivan\PL\repro.js:8:16)
at emitLookup (node:net:1414:5)
at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
at lookupAndConnectMultiple (node:net:1413:3)
at node:net:1359:7
at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
at lookupAndConnect (node:net:1358:5)
at Socket.connect (node:net:1255:5)
at Object.connect (node:_tls_wrap:1801:13) {
code: 'ERR_INVALID_IP_ADDRESS'
}
Node.js v20.16.0
Additional information
I am testing on the same machine, same code above. Just different nodejs
Version
20.16.0
Platform
Subsystem
No response
What steps will reproduce the bug?
Just run this
node repro.jsHow often does it reproduce? Is there a required condition?
You can repro it on node
v20+it works on nodev18What is the expected behavior? Why is that the expected behavior?
This is the expected behavior because we have defined a custom lookup method to resolve to this IP
What do you see instead?
Additional information
I am testing on the same machine, same code above. Just different nodejs