Skip to content

Node 10.8.0 does not support lookup on Agent #27695

Description

@firasdib
  • 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.

Activity

  1. added
    dnsIssues and PRs related to the dns subsystem.
    httpIssues and PRs related to the http subsystem.
    on May 14, 2019
  2. ktrongnhan commented on May 20, 2019

    @ktrongnhan

    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
    
  3. firasdib commented on May 20, 2019

    @firasdib
    Author
  4. ktrongnhan commented on May 20, 2019

    @ktrongnhan

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

  5. firasdib commented on May 25, 2019

    @firasdib
    Author

    @ktrongnhan I simply replaced the global agent like this:

    const http = require('http');
    
    http.globalAgent = new http.Agent({ lookup: customFunction });
  6. ktrongnhan commented on May 26, 2019

    @ktrongnhan

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

  7. bnoordhuis commented on Jul 3, 2019

    @bnoordhuis
    Member

    Closing, should be fixed by #25170.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    dnsIssues and PRs related to the dns subsystem.httpIssues and PRs related to the http subsystem.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions