Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node 10.8.0 does not support lookup on Agent #27695

Closed
firasdib opened this issue May 14, 2019 · 6 comments
Closed

Node 10.8.0 does not support lookup on Agent #27695

firasdib opened this issue May 14, 2019 · 6 comments
Labels
dns Issues and PRs related to the dns subsystem. http Issues or PRs related to the http subsystem.

Comments

@firasdib
Copy link

  • Version: 10.8.0
  • Platform: Linux
  • Subsystem: CentOS

The docs state you can specify your own lookup function for DNS resolution when creating an Agent. 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_agent

However, this option is not respected in v10.8.0. After upgrading to v12, it worked as intended.

@Fishrock123 Fishrock123 added dns Issues and PRs related to the dns subsystem. http Issues or PRs related to the http subsystem. labels May 14, 2019
@ktrongnhan
Copy link

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

@firasdib
Copy link
Author

firasdib commented May 20, 2019 via email

@ktrongnhan
Copy link

@firasdib
Could you give me a snippet to look at? A single line of code can save thousand words :)

@firasdib
Copy link
Author

@ktrongnhan I simply replaced the global agent like this:

const http = require('http');

http.globalAgent = new http.Agent({ lookup: customFunction });

@ktrongnhan
Copy link

@firasdib
#25170 has landed in v10.16.0-proposal. Seems like there will not be any change to the docs.

@bnoordhuis
Copy link
Member

bnoordhuis commented Jul 3, 2019

Closing, should be fixed by #25170.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
dns Issues and PRs related to the dns subsystem. http Issues or PRs related to the http subsystem.
Projects
None yet
Development

No branches or pull requests

4 participants