Skip to content

fix(batch): prevent race condition in batch queue process loop#3

Open
kbak wants to merge 1 commit intoinfra402:mainfrom
kbak:fix/batch-queue-race-condition
Open

fix(batch): prevent race condition in batch queue process loop#3
kbak wants to merge 1 commit intoinfra402:mainfrom
kbak:fix/batch-queue-race-condition

Conversation

@kbak
Copy link

@kbak kbak commented Feb 12, 2026

Summary

  • Fix race condition where the one-shot process_loop could exit after a single flush while new requests were being enqueued, leaving them stranded with no processor
  • The spawner would skip re-spawning because task_running was cleared outside the pending lock, creating a window where enqueue() sees task_running=true but the task is about to exit
  • process_loop now continuously flushes every max_wait_ms and only exits when the queue is empty, atomically clearing task_running under the pending lock to close the race window

Test plan

  • Run existing batch settlement tests
  • Stress test with concurrent settle requests to verify no requests are dropped
  • Verify batch processor exits cleanly when queue drains

🤖 Generated with Claude Code

The one-shot process_loop could exit after a single flush while new
requests were being enqueued, leaving them stranded with no processor.
The spawner would skip re-spawning because task_running was cleared
outside the pending lock, creating a window where enqueue() sees
task_running=true but the task is about to exit.

Now process_loop continuously flushes every max_wait_ms and only exits
when the queue is empty, atomically clearing task_running under the
pending lock to close the race window.

Co-Authored-By: Claude Opus 4.6 <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