From 4ce116a884bd55d7046dbc999f329fa417414c00 Mon Sep 17 00:00:00 2001 From: Damien Neil Date: Tue, 10 Dec 2024 09:49:45 -0800 Subject: 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 Reviewed-by: Michael Pratt LUCI-TryBot-Result: Go LUCI --- src/runtime/time.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/runtime') 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. -- cgit v1.3-5-g9baa