Runtime: fix lost wakeup from late-arriving atomicWaitBroken wait notify - #1315
Open
andreas-karlsson wants to merge 2 commits into
Open
Runtime: fix lost wakeup from late-arriving atomicWaitBroken wait notify#1315andreas-karlsson wants to merge 2 commits into
andreas-karlsson wants to merge 2 commits into
Conversation
Collaborator
Author
|
Hello @andreaTP , I've seen the exciting new endive repo, but we haven't migrated yet, so I thought I'd contribute here first. Or maybe you want it the other way around? |
Collaborator
|
Hi @andreas-karlsson I do not have rights to merge PRs here. |
Collaborator
Author
|
@andreaTP ah, I see. I've already opened issue and PR in endive :) So what will happen to this repo? Frozen? |
Member
|
@andreas-karlsson we are happy to merge PRs here as well, I was only waiting for CI to pass before engaging. |
Collaborator
Author
|
@nilslice I don't think the failing CI is related to my changes? |
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 #1314
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.