mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
runtime: fix race condition between timer and event handler
This change fixes a race condition between beforeIdle waking up the innermost event handler and a timer causing a different goroutine to wake up at the exact same moment. This messes up the wasm event handling and leads to memory corruption. The solution is to make beforeIdle return the goroutine that must run next and have findrunnable pick this goroutine without considering timers again. Fixes #38093 Fixes #38574 Change-Id: Iffbe99411d25c2730953d1c8b0741fd892f8e540 Reviewed-on: https://go-review.googlesource.com/c/go/+/230178 Run-TryBot: Richard Musiol <neelance@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
This commit is contained in:
parent
7dbbb5bacf
commit
0452f9460f
5 changed files with 70 additions and 12 deletions
|
|
@ -2286,9 +2286,17 @@ stop:
|
|||
|
||||
// wasm only:
|
||||
// If a callback returned and no other goroutine is awake,
|
||||
// then pause execution until a callback was triggered.
|
||||
if beforeIdle(delta) {
|
||||
// At least one goroutine got woken.
|
||||
// then wake event handler goroutine which pauses execution
|
||||
// until a callback was triggered.
|
||||
gp, otherReady := beforeIdle(delta)
|
||||
if gp != nil {
|
||||
casgstatus(gp, _Gwaiting, _Grunnable)
|
||||
if trace.enabled {
|
||||
traceGoUnpark(gp, 0)
|
||||
}
|
||||
return gp, false
|
||||
}
|
||||
if otherReady {
|
||||
goto top
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue