]> Cypherpunks repositories - gostls13.git/commit
net: fix a race in TestLookupContextCancel
authorBryan C. Mills <bcmills@google.com>
Tue, 8 Feb 2022 22:09:40 +0000 (17:09 -0500)
committerBryan Mills <bcmills@google.com>
Wed, 9 Feb 2022 20:12:16 +0000 (20:12 +0000)
commit846c06d33b55493caa7b49738cb7c85218fa0fd0
tree6dff70261e7999b96c2d8eff1a1dc9b9b2934a36
parent9cec77ac11b012283e654b423cf85cf9976bedd9
net: fix a race in TestLookupContextCancel

If the actual DNS lookup in LookupIPAddr completes quickly enough,
it may succeed even if the passed-in Context is already canceled.
That would (rarely) cause TestLookupContextCancel to fail due to an
unexpectedly-nil error.

This change uses the existing testHookLookupIP hook to delay the
cancellation until the lookup has started (to try to provoke the code
path for which the test was added), and then block the lookup result
until LookupIPAddr has noticed it.

Fixes #51084
Updates #22724

Change-Id: I331ac61a652ac88f6d4c85bf62466237b76d53ed
Reviewed-on: https://go-review.googlesource.com/c/go/+/384237
Trust: Bryan Mills <bcmills@google.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/net/lookup_test.go