-
Notifications
You must be signed in to change notification settings - Fork 18.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
registry: isCIDRMatch: avoid performing DNS lookups if not needed #48999
Conversation
Failure is unrelated; will be fixed by; |
Skip all code if there's nothing to match against. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
3a732a9
to
d31c28d
Compare
isCIDRMatch defaulted to trying to resolve a hostname to get its IP-address(es) before trying if the given host was an IP address already. Let's reverse the order so that we can avoid performing a DNS lookup when it's not needed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
d31c28d
to
28a700b
Compare
if host == "127.0.0.1" { | ||
// I believe in future Go versions this will fail, so let's fix it later | ||
return net.LookupIP(host) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we're now skipping lookupIP
if it's an IP address, this case can be removed; let me update
This one's really flaky recently;
|
if len(cidrs) == 0 { | ||
return false | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sadly this currently doesn't help, as we're unconditionally initialising RepoInfo
with localhost CIDRs; while that's relevant for some uses of RepoInfo
, it's not for others, and I'll look for follow-ups to split those use-cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
A colleague found that isCIDRMatch (called indirectly through ParseRepositoryInfo), is performing DNS lookups. These lookups are related to it assuming is being run as part of the docker engine, and has to check whether the registry is marked as "insecure" in daemon config.
A consequence of this was that tests were slow as they were using
foo.example.com
(and similar) domains.This is a first set of changes to avoid performing DNS lookups; the core problem lies in
newRegistryInfo
(which is called as part of the above) always tries to propagate all information, including whether the registry is marked "secure". This information is not used in any way for getting the key to use for storing auth, but requires some additional changes to remove (which I'll do in follow-ups);moby/registry/config.go
Lines 386 to 405 in 321f9c2