]> Cypherpunks repositories - gostls13.git/commit
crypto/tls: use runtime.Gosched instead of time.After in TestCertCache
authorMichael Anthony Knyszek <mknyszek@google.com>
Thu, 8 May 2025 19:03:37 +0000 (19:03 +0000)
committerGopher Robot <gobot@golang.org>
Thu, 8 May 2025 22:17:20 +0000 (15:17 -0700)
commitf4e37b8afc01253567fddbdd68ec35632df86b62
tree5d87def3a6c0ead88825b86e9835a55b27411833
parentcad1fc52076f1368d79aa833c1810ae050df57e6
crypto/tls: use runtime.Gosched instead of time.After in TestCertCache

I noticed a failure of this test on a linux/amd64 builder and reproduced
it locally. I can only really reproduce it in a stress test when I
overload my system (`stress2 ./tls.test -test.run=TestCertCache`) but
this points to the root of the problem: it's possible for a timer to get
delayed and the timeout fires before we ever get the chance to check.

After copious debugging printlns, this is essentially what I'd observed.
There would only be one failed check of the reference count from before
it was updated.

Change the test to be a busy-loop again, but call runtime.Gosched. This
is also what we do for the os.Root tests, and in hindsight should've
been my go-to. This has a much higher likelihood of executing promptly.

We may want to go back and understand why the 1 ms timer would fire so
hilariously late the second time. This might be a real bug. For now,
this change makes the test more stable. It no longer fails when it's
hammered under `stress2`.

Fixes #73637.

Change-Id: I316bd9e30946f4c055e61d179c4efc5fe029c608
Reviewed-on: https://go-review.googlesource.com/c/go/+/671175
Auto-Submit: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Michael Pratt <mpratt@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
src/crypto/tls/cache_test.go