diff options
author | Cezar Sa Espinola <cezarsa@gmail.com> | 2019-03-07 12:52:16 -0300 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2019-03-08 01:21:52 +0000 |
commit | e341bae08d75611adea6566c1d01c1e3a0de57f9 (patch) | |
tree | a6b016e81daed4743fd1953b90a2641f694d3f41 /src/net/lookup.go | |
parent | 6a9da69147a3b32e48f8dfea8c82f5975af9cc62 (diff) | |
download | go-e341bae08d75611adea6566c1d01c1e3a0de57f9.tar.gz go-e341bae08d75611adea6566c1d01c1e3a0de57f9.zip |
net: use network and host as singleflight key during lookupIP
In CL 120215 the cgo resolver was changed to have different logic based
on the network being queried. However, the singleflight cache key wasn't
updated to also include the network. This way it was possible for
concurrent queries to return the result for the wrong network.
This CL changes the key to include both network and host, fixing the
problem.
Fixes #30521
Change-Id: I8b41b0ce1d9a02d18876c43e347654312eba22fc
Reviewed-on: https://go-review.googlesource.com/c/go/+/166037
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'src/net/lookup.go')
-rw-r--r-- | src/net/lookup.go | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/src/net/lookup.go b/src/net/lookup.go index e10889331e..08e8d01385 100644 --- a/src/net/lookup.go +++ b/src/net/lookup.go @@ -262,8 +262,9 @@ func (r *Resolver) lookupIPAddr(ctx context.Context, network, host string) ([]IP // only the values in context. See Issue 28600. lookupGroupCtx, lookupGroupCancel := context.WithCancel(withUnexpiredValuesPreserved(ctx)) + lookupKey := network + "\000" + host dnsWaitGroup.Add(1) - ch, called := r.getLookupGroup().DoChan(host, func() (interface{}, error) { + ch, called := r.getLookupGroup().DoChan(lookupKey, func() (interface{}, error) { defer dnsWaitGroup.Done() return testHookLookupIP(lookupGroupCtx, resolverFunc, network, host) }) @@ -280,7 +281,7 @@ func (r *Resolver) lookupIPAddr(ctx context.Context, network, host string) ([]IP // let the lookup continue uncanceled, and let later // lookups with the same key share the result. // See issues 8602, 20703, 22724. - if r.getLookupGroup().ForgetUnshared(host) { + if r.getLookupGroup().ForgetUnshared(lookupKey) { lookupGroupCancel() } else { go func() { |