-
Notifications
You must be signed in to change notification settings - Fork 29.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UDP/dgram performs unnecessary DNS lookups #39468
Comments
Previously, we would call dns.lookup even for IP addresses in Socket#connect. This now skips that to improve performance. Fixes: nodejs#39468
Previously, we would call dns.lookup even for IP addresses in Socket#connect. This now skips that to improve performance. Fixes: nodejs#39468
Previously, we would call dns.lookup even for IP addresses in Socket#connect. This now skips that to improve performance. Fixes: nodejs#39468
I suspect there is a misconception here. The Lines 155 to 164 in b3723fa
So, the fact that |
Trying to come up with a test, the easiest I could find is to get an invalid DNS server, and if it is true that for ip it does lookup, it would fail the same way it fails for a non-ip name. NodeJS We can use docker with an invalid DNS server:
Test 1 - call a non-ip name:Calling require("dgram").
createSocket({ type: "udp4" }).
connect(1234, "foobar", (err) => {
console.log("Socket connected", { err });
}); ResultSocket connected {
err: Error: getaddrinfo EAI_AGAIN foobar
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:66:26)
at GetAddrInfoReqWrap.callbackTrampoline (internal/async_hooks.js:120:14) {
errno: 'EAI_AGAIN',
code: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: 'foobar'
}
} Test 2 - call an ip address:Calling require("dgram").
createSocket({ type: "udp4" }).
connect(1234, "192.168.0.1", (err) => {
console.log("Socket connected", { err });
}); Result
So, I am quite convinced it is working properly. |
To test conclusively, I think you would want to actually run a real DNS server with logging, just in case there's something going on in the Docker image and/or That being said, I think we should still move forward with the change proposed in this ticket.
|
Version
14.x
Platform
All
Subsystem
dgram
What steps will reproduce the bug?
It appears that UDP/dgram connections perform unnecessary DNS lookups when an IP address is provided as the address to connect to.
The issue is easily demonstrated via this snippet:
Output:
How often does it reproduce? Is there a required condition?
These lookups appear to happen 100% of the time a UDP socket connects to an address that is a raw IP address.
What is the expected behavior?
DNS lookups only occur when the address is a hostname.
What do you see instead?
No response
Additional information
Note that the
net
module contains code that bypassesdns.lookup()
when the target address is a valid IP address. It seems like we could improve efficiency by adding a similar check todgram
without breaking compatibility.The text was updated successfully, but these errors were encountered: