aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/synctest.go
diff options
context:
space:
mode:
authorDamien Neil <dneil@google.com>2025-06-02 09:26:27 -0700
committerGopher Robot <gobot@golang.org>2025-06-04 09:20:21 -0700
commit3432c68467d50ffc622fed230a37cd401d82d4bf (patch)
tree68e8152e4ba53aef6cb685d95ccc891b14d8c272 /src/runtime/synctest.go
parent1aa336209363d9715e145244c7b22620ac0f0584 (diff)
downloadgo-3432c68467d50ffc622fed230a37cd401d82d4bf.tar.xz
runtime: make bubbled timers more consistent with unbubbled
This CL makes two changes to reduce the predictability with which bubbled timers fire. When asynctimerchan=0 (the default), regular timers with an associated channel are only added to a timer heap when some channel operation is blocked on that channel. This allows us to garbage collect unreferenced, unstopped timers. Timers in a synctest bubble, in contrast, are always added to the bubble's timer heap. This CL changes bubbled timers with a channel to be handled the same as unbubbled ones, adding them to the bubble's timer heap only when some channel operation is blocked on the timer's channel. This permits unstopped bubbled timers to be garbage collected, but more importantly it makes all timers past their deadline behave identically, regardless of whether they are in a bubble. This CL also changes timer scheduling to execute bubbled timers immediately when possible rather than adding them to a heap. Timers in a bubble's heap are executed when the bubble is idle. Executing timers immediately avoids creating a predictable order of execution. For #73850 Fixes #73934 Change-Id: If82e441546408f780f6af6fb7f6e416d3160295d Reviewed-on: https://go-review.googlesource.com/c/go/+/678075 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/synctest.go')
-rw-r--r--src/runtime/synctest.go3
1 files changed, 1 insertions, 2 deletions
diff --git a/src/runtime/synctest.go b/src/runtime/synctest.go
index f676afa20d..c837c792a5 100644
--- a/src/runtime/synctest.go
+++ b/src/runtime/synctest.go
@@ -185,7 +185,6 @@ func synctestRun(f func()) {
}
const synctestBaseTime = 946684800000000000 // midnight UTC 2000-01-01
bubble.now = synctestBaseTime
- bubble.timers.bubble = bubble
lockInit(&bubble.mu, lockRankSynctest)
lockInit(&bubble.timers.mu, lockRankTimers)
@@ -213,7 +212,7 @@ func synctestRun(f func()) {
// so timer goroutines inherit their child race context from g0.
curg := gp.m.curg
gp.m.curg = nil
- gp.bubble.timers.check(gp.bubble.now)
+ gp.bubble.timers.check(bubble.now, bubble)
gp.m.curg = curg
})
gopark(synctestidle_c, nil, waitReasonSynctestRun, traceBlockSynctest, 0)