{{ message }}
dgram: skip dns.lookup() for literal IP addresses#64131
Draft
BridgeAR wants to merge 2 commits into
Draft
Conversation
Collaborator
72c64f2 to
dd5a8f8
Compare
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>
dd5a8f8 to
8dbffe4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
dgramresolved the destination through the socket lookup (dns.lookup()bydefault) on every unconnected
send()and on the implicit first-send bind, evenwhen the destination was already a literal IP. The address resolves to itself,
so the call is redundant, and tools that instrument
dns.lookup()record alookup for every datagram sent to an IP.
Two commits, separated so the patch can land independently of the breaking part:
dns.lookup()for a literal IP of thesocket's family; a custom
lookupis still consulted.lookuptoo, for a literal IP of thesocket's family.
Why
net.connect()already skips resolution for a literal IP host before it evenreads
options.lookup;http/tlsinherit that.dgramwas the outlier,re-resolving per send. Aligning it removes the redundant work and the
per-datagram
dns.lookup()instrumentation noise. Commit 2 changes the contractfor a custom
lookupthat expected to be invoked for IP addresses, so it iskept separate.
Test plan
test/parallel/test-dgram-default-lookup-ip.js(new): an IPv4 send and a udp6bind to a literal IP do not call
dns.lookup(); a mismatched family (::1ona udp4 socket) still resolves through it.
test/parallel/test-dgram-custom-lookup.js: a customlookupis not calledfor a literal IP; host names still go through it.
Refs: DataDog/dd-trace-js#2984