Skip to content

Runtime: fix lost wakeup from late-arriving atomicWaitBroken wait notify - #1315

Open
andreas-karlsson wants to merge 2 commits into
dylibso:mainfrom
andreas-karlsson:broken-wait-notify
Open

Runtime: fix lost wakeup from late-arriving atomicWaitBroken wait notify#1315
andreas-karlsson wants to merge 2 commits into
dylibso:mainfrom
andreas-karlsson:broken-wait-notify

Conversation

@andreas-karlsson

Copy link
Copy Markdown
Collaborator

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.

@andreas-karlsson

Copy link
Copy Markdown
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?

@andreaTP

Copy link
Copy Markdown
Collaborator

Hi @andreas-karlsson I do not have rights to merge PRs here.

@andreas-karlsson

Copy link
Copy Markdown
Collaborator Author

@andreaTP ah, I see. I've already opened issue and PR in endive :) So what will happen to this repo? Frozen?

@nilslice

Copy link
Copy Markdown
Member

@andreas-karlsson we are happy to merge PRs here as well, I was only waiting for CI to pass before engaging.

@nilslice
nilslice removed the request for review from andreaTP July 20, 2026 20:04
@andreas-karlsson

Copy link
Copy Markdown
Collaborator Author

@nilslice I don't think the failing CI is related to my changes?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

atomicWait can steal a wakeup meant for an already-parked thread

3 participants