]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.23] runtime: if stop/reset races with running timer, return corre...
authorIan Lance Taylor <iant@golang.org>
Sat, 7 Sep 2024 00:19:34 +0000 (17:19 -0700)
committerGopher Robot <gobot@golang.org>
Fri, 27 Sep 2024 18:23:47 +0000 (18:23 +0000)
commit3b2e846e11d0c31a556b198f6c700745de5c9780
treeee0878e746bdb14fd55a68487661a8ffa09545c7
parentfbddfae62f19b5f04555aa593970ac4c6f5a38e5
[release-branch.go1.23] runtime: if stop/reset races with running timer, return correct result

The timer code is careful to ensure that if stop/reset is called
while a timer is being run, we cancel the run. However, the code
failed to ensure that in that case stop/reset returned true,
meaning that the timer had been stopped. In the racing case
stop/reset could see that t.when had been set to zero,
and return false, even though the timer had not and never would fire.

Fix this by tracking whether a timer run is in progress,
and using that to reliably detect that the run was cancelled,
meaning that stop/reset should return true.

For #69312
Fixes #69333

Change-Id: I78e870063eb96650638f12c056e32c931417c84a
Reviewed-on: https://go-review.googlesource.com/c/go/+/611496
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit 2ebaff4890596ed6064e2dcbbe5e68bc93bed882)
Reviewed-on: https://go-review.googlesource.com/c/go/+/616096
Reviewed-by: Ian Lance Taylor <iant@google.com>
Commit-Queue: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
src/runtime/time.go
src/time/sleep_test.go