Skip to content

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

Open
BridgeAR wants to merge 1 commit into
nodejs:mainfrom
BridgeAR:BridgeAR/2026-06-25-dgram-skip-ip-lookup
Open

dgram: skip dns.lookup() for literal IP addresses#64131
BridgeAR wants to merge 1 commit 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

Review requested:

  • @nodejs/net
  • @nodejs/performance

@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 3 times, most recently from dd5a8f8 to 8dbffe4 Compare June 25, 2026 18:02
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 8dbffe4 to edb15d7 Compare June 30, 2026 16:13
@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jun 30, 2026
@BridgeAR BridgeAR marked this pull request as ready for review June 30, 2026 16:21

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

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. semver-major PRs that contain breaking changes and should be released in the next major version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants