atomicWait can steal a wakeup meant for an already-parked thread
- Dominant language
- Java
- Stars
- 1.1k
- Forks
- 71
- PR merge metrics
- No merged PRs in 30d
Description
`atomicNotify` should only be able to wake threads that are already parked in `atomicWait`. Because of how the pending-wakeup permit is tracked, a thread that calls atomicWait after a notify has already fired can consume that permit and return immediately — without ever actually waiting — even though it wasn't parked when the notify happened. This steals the wakeup from the thread that was legitimately parked, which then has no way to know it needs to re-wait and can sleep forever.
Discovered via deadlocks in an otherwise-correct rw-lock implementation built on top of atomicWait/atomicNotify.
Contributor guide
Research direction
Start by locating the atomicWait and atomicNotify implementations and tracing how the pending-wakeup permit is tracked. Reproduce the reported interaction with an already-parked thread and the later atomicWait call, then add a regression test showing that the parked thread receives the wakeup without a later waiter consuming it.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, wasm
- Domain
- operating-systems
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100