fix(shared): avoid lost wakeups when canceling Acquire - #3629
Closed
HeyiSun wants to merge 3 commits into
Closed
Conversation
HeyiSun
requested review from
ValentaTomas,
dobrac and
jakubno
as code owners
September 8, 2026 09:26
Member
|
Merged in a586d1e |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I noticed this while reading through the project code. If cancellation broadcasts after the context check but before
Wait,Acquirecan stay blocked until another semaphore update wakes it. This can leave sandbox resume handlers blocked past the 15-second wait for a startup slot, even after the caller times out. Canceled storage uploads can get stuck waiting for a slot too.The callback now takes the condition lock before broadcasting. I added a regression test for that ordering; it fails on the old code and passes with the fix.
Reproduction
The original callback allows this ordering:
The test pauses
Acquireafter its context check, cancels the context, then lets it enterWait. Tested on Go 1.26.6:With the original semaphore implementation substituted using Go's
-overlay, keeping the test unchanged:With the fix,
Acquirereturnscontext.Canceledwithout an extra wakeup. The test passed 100 times each with 1, 2 and 8 processors. The full utils tests also pass with-race.