]> Cypherpunks repositories - gostls13.git/commit
[release-branch.go1.14] runtime: prevent preemption while timer is in timerModifying
authorMichael Anthony Knyszek <mknyszek@google.com>
Wed, 25 Mar 2020 16:41:20 +0000 (16:41 +0000)
committerIan Lance Taylor <iant@golang.org>
Wed, 25 Mar 2020 20:55:10 +0000 (20:55 +0000)
commitb43b463d8fd3b15e9feb5156ff13b51ffa6f4599
tree2087caf9991fb6488ec35df77ae86c846480999f
parent21f453b848405dee74e5d1d8863d28a3db4758f2
[release-branch.go1.14] runtime: prevent preemption while timer is in timerModifying

Currently if a goroutine is preempted while owning a timer in the
timerModifying state, it could self-deadlock. When the goroutine is
preempted and calls into the scheduler, it could call checkTimers. If
checkTimers encounters the timerModifying timer and calls runtimer on
it, then runtimer will spin, waiting for that timer to leave the
timerModifying state, which it never will.

So far we got lucky that for the most part that there were no preemption
points while timerModifying is happening, however CL 221077 seems to
have introduced one, leading to sporadic self-deadlocks.

This change disables preemption explicitly while a goroutines holds a
timer in timerModifying. Since only checkTimers (and thus runtimer) is
called from the scheduler, this is sufficient to prevent
preemption-based self-deadlocks.

For #38070
Fixes #38072

Change-Id: Idbfac310889c92773023733ff7e2ff87e9896f0c
Reviewed-on: https://go-review.googlesource.com/c/go/+/225497
Run-TryBot: Michael Knyszek <mknyszek@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
(cherry picked from commit e8be350d78f3fd21b0fab4cc6909c03fe21f1640)
Reviewed-on: https://go-review.googlesource.com/c/go/+/225521
Run-TryBot: Ian Lance Taylor <iant@golang.org>
src/runtime/time.go