Runtime: fix lost wakeup from late-arriving atomicWaitBroken wait notify#107
Merged
andreaTP merged 2 commits intoJul 20, 2026
Merged
Conversation
Comment on lines
+119
to
+122
| for (Thread t : threads) { | ||
| final long remaining = Long.max(10, joinDeadline - System.currentTimeMillis()); | ||
| t.join(remaining); | ||
| } |
Contributor
Author
There was a problem hiding this comment.
There's actually no point in waiting for these threads to join. I could replace this loop with just a sleep until deadline + some leeway. We still expect no thread to be alive.
andreaTP
approved these changes
Jul 20, 2026
andreaTP
left a comment
Contributor
There was a problem hiding this comment.
Great PR as usual @andreas-karlsson , thanks for the help!
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.
Fixes #106
A pending wakeup left behind by atomicNotify could be stolen by an atomicWait call that arrives after the notify, letting it return without ever waiting — while the thread the wakeup was actually meant for gets no signal and can sleep forever (lost wakeup / deadlock).
Fixes ByteArrayMemory/ByteBufferMemory by tagging each WaitState with a generation counter, bumped on every notify. A waiter may only consume a pending wakeup minted since it registered, so late arrivals wait for the next notify instead of stealing the current one.
Split into two commits for review: a regression test that reproduces the steal (fails on main), then the fix. Also adds a stress test that drives a rw-lock built on atomicWait/atomicNotify under contention, to catch this class of bug more broadly.