Skip to content

fix: use put_nowait to avoid race condition on queue full check#43

Draft
hussein-awala wants to merge 1 commit intomainfrom
fix/queue-full-race-condition
Draft

fix: use put_nowait to avoid race condition on queue full check#43
hussein-awala wants to merge 1 commit intomainfrom
fix/queue-full-race-condition

Conversation

@hussein-awala
Copy link
Copy Markdown
Owner

Summary

  • The previous code checked queue.full() then called await queue.put() as separate operations
  • Between the check and the put, another coroutine could add an item (after yielding at await), causing the put to block unexpectedly or the check to be stale
  • Fix: use put_nowait() and catch asyncio.QueueFull to make the check-and-put atomic

Test plan

  • test_max_queue_size still passes
  • All unit tests pass

🤖 Generated with Claude Code

The previous code checked queue.full() then called queue.put() as
separate operations. Between the check and the put, another coroutine
could add an item, causing the put to block unexpectedly. Using
put_nowait() and catching QueueFull makes the operation atomic.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant