dgram: skip dns.lookup() for literal IP addresses by BridgeAR · Pull Request #64131 · nodejs/node · GitHub
Skip to content

dgram: skip dns.lookup() for literal IP addresses#64131

Draft
BridgeAR wants to merge 2 commits into
nodejs:mainfrom
BridgeAR:BridgeAR/2026-06-25-dgram-skip-ip-lookup
Draft

dgram: skip dns.lookup() for literal IP addresses#64131
BridgeAR wants to merge 2 commits into
nodejs:mainfrom
BridgeAR:BridgeAR/2026-06-25-dgram-skip-ip-lookup

Conversation

@BridgeAR

Copy link
Copy Markdown
Member

Summary

dgram resolved the destination through the socket lookup (dns.lookup() by
default) on every unconnected send() and on the implicit first-send bind, even
when the destination was already a literal IP. The address resolves to itself,
so the call is redundant, and tools that instrument dns.lookup() record a
lookup for every datagram sent to an IP.

Two commits, separated so the patch can land independently of the breaking part:

  1. (semver-patch) Skip the default dns.lookup() for a literal IP of the
    socket's family; a custom lookup is still consulted.
  2. (semver-major) Skip a user-supplied lookup too, for a literal IP of the
    socket's family.

Why

net.connect() already skips resolution for a literal IP host before it even
reads options.lookup; http/tls inherit that. dgram was the outlier,
re-resolving per send. Aligning it removes the redundant work and the
per-datagram dns.lookup() instrumentation noise. Commit 2 changes the contract
for a custom lookup that expected to be invoked for IP addresses, so it is
kept separate.

Test plan

  • test/parallel/test-dgram-default-lookup-ip.js (new): an IPv4 send and a udp6
    bind to a literal IP do not call dns.lookup(); a mismatched family (::1 on
    a udp4 socket) still resolves through it.
  • test/parallel/test-dgram-custom-lookup.js: a custom lookup is not called
    for a literal IP; host names still go through it.

Refs: DataDog/dd-trace-js#2984

@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

@nodejs-github-bot nodejs-github-bot added dgram Issues and PRs related to the dgram subsystem / UDP. needs-ci PRs that need a full CI run. labels Jun 25, 2026
@BridgeAR BridgeAR force-pushed the BridgeAR/2026-06-25-dgram-skip-ip-lookup branch 2 times, most recently from 72c64f2 to dd5a8f8 Compare June 25, 2026 16:02
BridgeAR added 2 commits June 25, 2026 19:58
Every unconnected send(), and the implicit bind on first send,
resolved the destination through dns.lookup() even when it was
already a literal IP. The address resolves to itself, so the call is
redundant, and tools that instrument dns.lookup() record a lookup for
every datagram sent to an IP.

Skip the resolver for a literal IP of the socket's family and report
it on the next tick, keeping dns.lookup()'s asynchronous contract. A
custom lookup function is still consulted for every address.

Refs: DataDog/dd-trace-js#2984
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
A user-supplied lookup function is no longer called when the
destination is a literal IP of the socket's family; the address is
used directly, matching net.connect(), which skips the lookup for a
literal IP host before consulting options.lookup. This is a breaking
change for a lookup that expected to be invoked for IP addresses.

Refs: DataDog/dd-trace-js#2984
Signed-off-by: Ruben Bridgewater <ruben@bridgewater.de>
@BridgeAR BridgeAR force-pushed the BridgeAR/2026-06-25-dgram-skip-ip-lookup branch from dd5a8f8 to 8dbffe4 Compare June 25, 2026 18:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dgram Issues and PRs related to the dgram subsystem / UDP. needs-ci PRs that need a full CI run.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants