-
Notifications
You must be signed in to change notification settings - Fork 17.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
runtime: prevent send on closed channel in wakeableSleep
Currently wakeableSleep has a race where, although stopTimer is called, the timer could be queued already and fire *after* the wakeup channel is closed. Fix this by protecting wakeup with a lock used on the close and wake paths and assigning the wakeup to nil on close. The wake path then ignores a nil wakeup channel. This fixes the problem by ensuring that a failure to stop the timer only results in the timer doing nothing, rather than trying to send on a closed channel. The addition of this lock requires some changes to the static lock ranking system. Thiere's also a second problem here: the timer could be delayed far enough into the future that when it fires, it observes a non-nil wakeup if the wakeableSleep has been re-initialized and reset. Fix this problem too by allocating the wakeableSleep on the heap and creating a new one instead of reinitializing the old one. The GC will make sure that the reference to the old one stays alive for the timer to fire, but that timer firing won't cause a spurious wakeup in the new one. Change-Id: I2b979304e755c015d4466991f135396f6a271069 Reviewed-on: https://go-review.googlesource.com/c/go/+/542335 Reviewed-by: Michael Pratt <[email protected]> Commit-Queue: Michael Knyszek <[email protected]> Auto-Submit: Michael Knyszek <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Run-TryBot: Michael Knyszek <[email protected]>
- Loading branch information
Showing
4 changed files
with
49 additions
and
19 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters