diff --git a/src/runtime/time.go b/src/runtime/time.go index 81a4c6b79f..5db8a626b3 100644 --- a/src/runtime/time.go +++ b/src/runtime/time.go @@ -1126,13 +1126,7 @@ func (t *timer) unlockAndRun(now int64, bubble *synctestBubble) { // Note that we are running on a system stack, // so there is no chance of getg().m being reassigned // out from under us while this function executes. - gp := getg() - var tsLocal *timers - if bubble == nil { - tsLocal = &gp.m.p.ptr().timers - } else { - tsLocal = &bubble.timers - } + tsLocal := &getg().m.p.ptr().timers if tsLocal.raceCtx == 0 { tsLocal.raceCtx = racegostart(abi.FuncPCABIInternal((*timers).run) + sys.PCQuantum) } @@ -1184,11 +1178,7 @@ func (t *timer) unlockAndRun(now int64, bubble *synctestBubble) { if gp.racectx != 0 { throw("unexpected racectx") } - if bubble == nil { - gp.racectx = gp.m.p.ptr().timers.raceCtx - } else { - gp.racectx = bubble.timers.raceCtx - } + gp.racectx = gp.m.p.ptr().timers.raceCtx } if ts != nil { diff --git a/src/testing/synctest/synctest_test.go b/src/testing/synctest/synctest_test.go index 62f10d1b81..be91a0b13b 100644 --- a/src/testing/synctest/synctest_test.go +++ b/src/testing/synctest/synctest_test.go @@ -188,3 +188,18 @@ func TestNow(t *testing.T) { } }) } + +func TestSynctestTimerRaceCtxCrash(t *testing.T) { + for range 20 { + t.Run("", func(t *testing.T) { + synctest.Test(t, func(t *testing.T) { + for range 100 { + time.AfterFunc(1*time.Second, func() { + time.AfterFunc(0, func() {}) + }) + } + time.Sleep(2 * time.Second) + }) + }) + } +}