question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using an IP still invokes DNS lookup due to callback being defined on datagram send

See original GitHub issue

Hello!

We recently integrated datadog ontop of our existing monitoring solution and discovered a lot of DNS lookups for our statsd agent IP. We were specifically passing an IP so we wouldn’t have to resolve a host name.

It seems to be the fact that for UDP we are using: https://nodejs.org/docs/latest-v12.x/api/dgram.html#dgram_socket_send_msg_offset_length_port_address_callback

Which is being utilised here: https://github.com/brightcove/hot-shots/blob/master/lib/transport.js#L46-L87 through this API: https://github.com/brightcove/hot-shots/blob/master/lib/statsd.js#L314-L373

Since we are always passing a callback the following kicks in:

An optional callback function may be specified to as a way of reporting DNS errors or for determining when it is safe to reuse the buf object. DNS lookups delay the time to send for at least one tick of the Node.js event loop.

which seems to cause a DNS lookup: https://github.com/nodejs/node/issues/35130

By that post, there should be a quick path for DNS Lookup for IPs but I couldn’t find it. We’re seeing A LOT of requests for resolving DNS for an IP. Any recommendations on how/if we should cut these down?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:9
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
peeter-tombergcommented, Mar 29, 2021
0reactions
hjr3commented, Oct 14, 2022

Since https://github.com/brightcove/hot-shots/commit/a399dda99fb1bf2b15e53646b3ef5d8cbb0b90c9 landed in v9.2.0 you can do:

const client = new StatsD({
  host,
  port,
  udpSocketOptions: {
    type: 'udp4',
    lookup: (hostname, options, callback) => {
      // if IP address, bypass dns.lookup
      if (isIP(hostname)) {
        callback(null, hostname, 4);
        return;
      }

      // if a real hostname, then resolve using dns.lookup
      dns.lookup(hostname, options, callback);
    },
  },
});

Read more comments on GitHub >

github_iconTop Results From Across the Web

4.6. UDP Socket Programming: DNS
The Domain Name System (DNS) is a distributed database that resolves human-readable URLs (such as stuff.com or k12.county.edu ) into IP addresses.
Read more >
Send UDP Messages in Node.js Without dns.lookup
The issue is that our socket.send first tries to bind to a local address (e.g. 0.0.0.0 ), which calls our custom lookup function....
Read more >
UDP/datagram sockets | Node.js v19.3.0 Documentation
The only way to know for sure that the datagram has been sent is by using a callback . If an error occurs...
Read more >
dns_sd.h - Apple Open Source
The DNS Service Discovery API is part of Bonjour, Apple's implementation * of ... Then, later when a callback is eventually * invoked...
Read more >
Can I perform a DNS lookup (hostname to IP address) using ...
Yay, no server proxies needed. Pure JS can't. If you have a server script under the same domain that prints it out you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found