libnetwork: Sandbox.resolveName: slightly simplify locking

Simplify the lock/unlock cycle, and make the "lookupAlias" branch
more similar to the non-lookupAlias variant.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2023-08-17 12:50:54 +02:00
parent f549aaa205
commit d7a31cfb2d
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C

View file

@ -501,22 +501,22 @@ func (sb *Sandbox) resolveName(nameOrAlias string, networkName string, epList []
name := nameOrAlias
if lookupAlias {
var ok bool
ep.mu.Lock()
name, ok = ep.aliases[nameOrAlias]
alias, ok := ep.aliases[nameOrAlias]
ep.mu.Unlock()
if !ok {
continue
}
name = alias
} else {
// If it is a regular lookup and if the requested name is an alias
// don't perform a svc lookup for this endpoint.
ep.mu.Lock()
if _, ok := ep.aliases[nameOrAlias]; ok {
ep.mu.Unlock()
_, ok := ep.aliases[nameOrAlias]
ep.mu.Unlock()
if ok {
continue
}
ep.mu.Unlock()
}
ip, miss := nw.ResolveName(name, ipType)