diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-01-17 14:20:29 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2018-01-17 14:20:29 +0000 |
commit | c6d6367f848cfd8381aba41e035c5e7e873667c5 (patch) | |
tree | a218e98243463fc27f5053b4444e2544c63cd57a /libgo/go/net/lookup.go | |
parent | 9bff0086915f544fa648ea81131f035cb9ce79a4 (diff) |
libgo: update to Go1.10beta2 release
Reviewed-on: https://go-review.googlesource.com/87897
From-SVN: r256794
Diffstat (limited to 'libgo/go/net/lookup.go')
-rw-r--r-- | libgo/go/net/lookup.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/libgo/go/net/lookup.go b/libgo/go/net/lookup.go index c9f327050af..85e472932fc 100644 --- a/libgo/go/net/lookup.go +++ b/libgo/go/net/lookup.go @@ -8,6 +8,7 @@ import ( "context" "internal/nettrace" "internal/singleflight" + "sync" ) // protocols contains minimal mappings between internet protocol @@ -53,6 +54,10 @@ var services = map[string]map[string]int{ }, } +// dnsWaitGroup can be used by tests to wait for all DNS goroutines to +// complete. This avoids races on the test hooks. +var dnsWaitGroup sync.WaitGroup + const maxProtoLength = len("RSVP-E2E-IGNORE") + 10 // with room to grow func lookupProtocolMap(name string) (int, error) { @@ -189,9 +194,14 @@ func (r *Resolver) LookupIPAddr(ctx context.Context, host string) ([]IPAddr, err resolverFunc = alt } - ch := lookupGroup.DoChan(host, func() (interface{}, error) { + dnsWaitGroup.Add(1) + ch, called := lookupGroup.DoChan(host, func() (interface{}, error) { + defer dnsWaitGroup.Done() return testHookLookupIP(ctx, resolverFunc, host) }) + if !called { + dnsWaitGroup.Done() + } select { case <-ctx.Done(): |