Title: Custom DNS lookup failing on Node 20+, works on Node 18 · Issue #55762 · nodejs/node · GitHub
Open Graph Title: Custom DNS lookup failing on Node 20+, works on Node 18 · Issue #55762 · nodejs/node
X Title: Custom DNS lookup failing on Node 20+, works on Node 18 · Issue #55762 · nodejs/node
Description: 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 customDNSLo...
Open Graph Description: 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 res...
X Description: 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'); /...
Opengraph URL: https://github.com/nodejs/node/issues/55762
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Custom DNS lookup failing on Node 20+, works on Node 18","articleBody":"### Version\r\n\r\n20.16.0\r\n\r\n### Platform\r\n\r\n```text\r\nMicrosoft Windows NT 10.0.22621.0\r\nx64\r\n```\r\n\r\n\r\n### Subsystem\r\n\r\n_No response_\r\n\r\n### What steps will reproduce the bug?\r\n```js\r\nconst dns = require('dns');\r\nconst https = require('https');\r\n\r\n// Custom DNS resolution for github.com\r\nconst customDNSLookup = (hostname, options, callback) =\u003e {\r\n if (hostname === 'github.com') {\r\n // Using one of GitHub's IPs as an example\r\n return callback(null, '20.205.243.166', 4);\r\n } else {\r\n return dns.lookup(hostname, options, callback);\r\n }\r\n};\r\n\r\n// Make a test request using native https\r\nasync function testConnection() {\r\n const options = {\r\n hostname: 'github.com',\r\n path: '/',\r\n method: 'GET',\r\n headers: {\r\n 'Host': 'github.com'\r\n },\r\n agent: new https.Agent({\r\n rejectUnauthorized: false,\r\n lookup: customDNSLookup\r\n })\r\n };\r\n\r\n return new Promise((resolve, reject) =\u003e {\r\n const req = https.request(options, (res) =\u003e {\r\n console.log('Successfully connected to GitHub');\r\n console.log('Using IP:', '20.205.243.166');\r\n console.log('Status:', res.statusCode);\r\n resolve(res);\r\n });\r\n\r\n req.on('error', (error) =\u003e {\r\n console.error('Error:', error.message);\r\n reject(error);\r\n });\r\n\r\n req.end();\r\n });\r\n}\r\n\r\ntestConnection();\r\n```\r\n\r\nJust run this `node repro.js`\r\n\r\n### How often does it reproduce? Is there a required condition?\r\n\r\nYou can repro it on node `v20+` it works on node `v18`\r\n\r\n### What is the expected behavior? Why is that the expected behavior?\r\n\r\n```\r\nSuccessfully connected to GitHub\r\nUsing IP: 20.205.243.166\r\nStatus: 200\r\n```\r\nThis is the expected behavior because we have defined a custom lookup method to resolve to this IP\r\n\r\n### What do you see instead?\r\n\r\n```\r\nError: Invalid IP address: undefined\r\nnode:internal/process/promises:391\r\n triggerUncaughtException(err, true /* fromPromise */);\r\n ^\r\n\r\nTypeError [ERR_INVALID_IP_ADDRESS]: Invalid IP address: undefined\r\n at emitLookup (node:net:1465:17)\r\n at customDNSLookup (C:\\Aivan\\PL\\repro.js:8:16)\r\n at emitLookup (node:net:1414:5)\r\n at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)\r\n at lookupAndConnectMultiple (node:net:1413:3)\r\n at node:net:1359:7\r\n at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)\r\n at lookupAndConnect (node:net:1358:5)\r\n at Socket.connect (node:net:1255:5)\r\n at Object.connect (node:_tls_wrap:1801:13) {\r\n code: 'ERR_INVALID_IP_ADDRESS'\r\n}\r\n\r\nNode.js v20.16.0\r\n```\r\n\r\n### Additional information\r\n\r\nI am testing on the same machine, same code above. Just different nodejs\r\n","author":{"url":"https://github.com/geocine","@type":"Person","name":"geocine"},"datePublished":"2024-11-07T07:48:47.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":7},"url":"https://github.com/55762/node/issues/55762"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:91020d81-2255-82e3-6b26-750b307b8f71 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A120:78205:10098A:157C7B:6A4D8F2B |
| html-safe-nonce | 8a339174d0672f2c8e473c273ebcaaeac5880819ea3cc99c6dac7ef423529569 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMTIwOjc4MjA1OjEwMDk4QToxNTdDN0I6NkE0RDhGMkIiLCJ2aXNpdG9yX2lkIjoiNjkwMDIxMzUxNTQ1NDc0ODU5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 37d464ff9de31f0a920475b1d0555669ca1f0fbeb2829b3be5794d98220b89a1 |
| hovercard-subject-tag | issue:2640177389 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/nodejs/node/55762/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a2f14fa04c6ce67ad6fe918c9c284e25c66292effa1aae44ec876ac2dfcd3f54/nodejs/node/issues/55762 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a2f14fa04c6ce67ad6fe918c9c284e25c66292effa1aae44ec876ac2dfcd3f54/nodejs/node/issues/55762 |
| og:image:alt | 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 res... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | geocine |
| hostname | github.com |
| expected-hostname | github.com |
| None | 06b8a6144231bf3a234f1c2e9993861e07ce98a905912b114aa386c2d7e84b33 |
| turbo-cache-control | no-preview |
| go-import | github.com/nodejs/node git https://github.com/nodejs/node.git |
| octolytics-dimension-user_id | 9950313 |
| octolytics-dimension-user_login | nodejs |
| octolytics-dimension-repository_id | 27193779 |
| octolytics-dimension-repository_nwo | nodejs/node |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 27193779 |
| octolytics-dimension-repository_network_root_nwo | nodejs/node |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 74e2a9c78f1e38588de4f25885878349d721eedf |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width