Repository navigation
Node 10.8.0 does not support lookup on Agent #27695
Copy link
Copy link
Closed
Labels
dnsIssues and PRs related to the dns subsystem.Issues and PRs related to the dns subsystem.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
Description
Activity
- addeddnsIssues and PRs related to the dns subsystem.Issues and PRs related to the dns subsystem.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
on May 14, 2019 Custom lookup() DOES WORK as expected for me
- Version: 10.8.0
- Platform: Linux
- Subsystem: CentOS 7
Sample snippet
const http = require('http'); const agent = process.argv[2] === '--agent' ? new http.Agent({ lookup: (hostname, opts, cb) => { cb && cb(new Error('unresolved hostname'), null, null); } }) : null; const requestOptions = { hostname: 'google.com', agent, } const req = http.request(requestOptions, (res) => { res.on('data', () => { }); res.on('end', () => { console.log('request fulfilled'); }); }).end(); req.on('error', (e) => { console.error(`request error: ${e.message}`); });
Results
$ node index.js request fulfilled $ node index.js --agent request error: unresolved hostname google.com:80 $ node --version v10.8.0 $ uname -a Linux localhost.localdomain 3.10.0-957.12.2.el7.x86_64 #1 SMP Tue May 14 21:24:32 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux- My issue was with using the global agent. I should have specified that.
@firasdib
Could you give me a snippet to look at? A single line of code can save thousand words :)@ktrongnhan I simply replaced the global agent like this:
const http = require('http'); http.globalAgent = new http.Agent({ lookup: customFunction });
Closing, should be fixed by #25170.
Metadata
Metadata
Assignees
Labels
dnsIssues and PRs related to the dns subsystem.Issues and PRs related to the dns subsystem.httpIssues and PRs related to the http subsystem.Issues and PRs related to the http subsystem.
The docs state you can specify your own
lookupfunction for DNS resolution when creating anAgent. See https://nodejs.org/dist/latest-v10.x/docs/api/net.html#net_socket_connect_options_connectlistener and https://nodejs.org/dist/latest-v10.x/docs/api/http.html#http_class_http_agentHowever, this option is not respected in v10.8.0. After upgrading to v12, it worked as intended.