aboutsummaryrefslogtreecommitdiff
path: root/src/runtime
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2024-12-10 09:49:45 -0800
committerGopher Robot <gobot@golang.org>2024-12-10 19:51:25 +0000
commit4ce116a884bd55d7046dbc999f329fa417414c00 (patch)
treecc1f863bdb4d8494dceb66549eba189f53b4ed63 /src/runtime
parente6de1b2debe2bc7211f6f9cac4b64d7cd90f7c4e (diff)
downloadgo-4ce116a884bd55d7046dbc999f329fa417414c00.tar.xz
runtime: avoid panic in expired synctest timer chan read
When reading from time.Timer.C for an expired timer using a fake clock (in a synctest bubble), the timer will not be in a heap. Avoid a spurious panic claiming the timer moved between synctest bubbles. Drop the panic when a bubbled goroutine reads from a non-bubbled timer channel: We allow bubbled goroutines to access non-bubbled channels in general. Fixes #70741 Change-Id: I27005e46f4d0067cc6846d234d22766d2e05d163 Reviewed-on: https://go-review.googlesource.com/c/go/+/634955 Auto-Submit: Damien Neil <dneil@google.com> Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Diffstat (limited to 'src/runtime')
-rw-r--r--src/runtime/time.go10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/runtime/time.go b/src/runtime/time.go
index 7c6d798872..c22d39c089 100644
--- a/src/runtime/time.go
+++ b/src/runtime/time.go
@@ -1370,15 +1370,19 @@ func badTimer() {
// to send a value to its associated channel. If so, it does.
// The timer must not be locked.
func (t *timer) maybeRunChan() {
- if sg := getg().syncGroup; sg != nil || t.isFake {
+ if t.isFake {
t.lock()
var timerGroup *synctestGroup
if t.ts != nil {
timerGroup = t.ts.syncGroup
}
t.unlock()
- if sg == nil || !t.isFake || sg != timerGroup {
- panic(plainError("timer moved between synctest groups"))
+ sg := getg().syncGroup
+ if sg == nil {
+ panic(plainError("synctest timer accessed from outside bubble"))
+ }
+ if timerGroup != nil && sg != timerGroup {
+ panic(plainError("timer moved between synctest bubbles"))
}
// No need to do anything here.
// synctest.Run will run the timer when it advances its fake clock.