Skip to content

dgram: skip dns lookup for IPs #39473

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

evanlucas
Copy link
Contributor

Previously, we would call dns.lookup even for IP addresses
in Socket#connect. This now skips that to improve performance.

Fixes: #39468

@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 Jul 20, 2021
@schmod
Copy link

schmod commented Jul 20, 2021

I'd avoided PRing this myself, because I couldn't figure out the best way to share isIP between net and dgram – I don't think we want dgram to depend on net, because it seems like it could introduce subtle changes to the order that modules load, which seems like it could break many APM implementations.

@evanlucas
Copy link
Contributor Author

@schmod, good point, I got a rebase conflict somehow :/ so have to fix that regardless. With it loading internal/net for isIP, I'm not sure that would change anything as far as module load time?

@evanlucas evanlucas marked this pull request as draft July 20, 2021 16:22
@evanlucas evanlucas force-pushed the evanlucas/udpdnslookup branch from 32feb15 to ed6bfef Compare July 20, 2021 16:44
@evanlucas evanlucas marked this pull request as ready for review July 20, 2021 17:06
@schmod
Copy link

schmod commented Jul 20, 2021

With it loading internal/net for isIP, I'm not sure that would change anything as far as module load time?

True, I'm not really worried about that. It's more about whether or not anybody's hot-patching any modules used downstream of net.

That all being said, that sounds like an extreme edge-case, and might not be worth worrying about?

@jasnell
Copy link
Member

jasnell commented Jul 20, 2021

While it may seem odd, this may be a breaking (semver-major) change. User code is permitted to provide a custom dns lookup function when the dgram/udp socket is created. Prior to this change, that function would be called for IP address values.

@jasnell jasnell added the semver-major PRs that contain breaking changes and should be released in the next major version. label Jul 20, 2021
@jasnell
Copy link
Member

jasnell commented Jul 20, 2021

This should include (a) a test case that verifies that the lookup function is not called and (b) a doc update indicating that a custom lookup function will not be invoked when the address is an IP address.

@schmod
Copy link

schmod commented Jul 20, 2021

While it may seem odd, this may be a breaking (semver-major) change. User code is permitted to provide a custom dns lookup function when the dgram/udp socket is created. Prior to this change, that function would be called for IP address values.

We could preserve the current behavior if a custom lookup is provided, and postpone the breaking change to the next major release...

Previously, we would call dns.lookup even for IP addresses
in Socket#connect. This now skips that to improve performance.

Fixes: nodejs#39468
They are currently failing due to us not emitting the
appropriate addressType in the lookup event.
@evanlucas evanlucas force-pushed the evanlucas/udpdnslookup branch from ed6bfef to 6ee0ab0 Compare August 5, 2021 12:49
@evanlucas evanlucas marked this pull request as draft August 5, 2021 12:49
@JackFreelander
Copy link

@evanlucas - Would it be possible to revive this PR and complete the fix? There seems to be no work-around for dgram's socket implementation invoking DNS resolution on every single .send() call without this fix. It would be great to have this.

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.

UDP/dgram performs unnecessary DNS lookups
5 participants