Fix: Queue Interruption Race Condition & Interruption Gap in asyncMaybe/asyncInterrupt
This PR addresses issues in ZIO’s concurrency primitives:
1. Fixes Race Condition in Queue#take
Interruption (#9973)
- Problem: There was a rare but critical race condition where interrupting a fiber waiting on
Queue#take
could cause an item to disappear from the queue.
- Solution:
- Introduced a
claimed
flag for takers to ensure that once a taker is matched, the item is either delivered or remains in the queue.
- The promise completion is now uninterruptible, and only unclaimed takers are removed on interruption.
- Tests: Added a dedicated test to reliably reproduce and verify the fix.
2. Closes Interruption Gap in asyncMaybe
/asyncInterrupt
(#9974)
- Problem: There was a small window where a fiber could be interrupted after an immediate result was returned from
asyncMaybe
or asyncInterrupt
, but before the result was delivered.
- Solution: Immediate results from these methods are now wrapped in
uninterruptible
, closing the gap.
- Tests: Added a JVM-specific test to stress this scenario and confirm the fix.
Thanks for reviewing! If you have any questions or want more details on the approach, let me know.
/claim #9973