fix(batch): prevent race condition in batch queue process loop#3
Open
kbak wants to merge 1 commit intoinfra402:mainfrom
Open
fix(batch): prevent race condition in batch queue process loop#3kbak wants to merge 1 commit intoinfra402:mainfrom
kbak wants to merge 1 commit intoinfra402:mainfrom
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
process_loopcould exit after a single flush while new requests were being enqueued, leaving them stranded with no processortask_runningwas cleared outside the pending lock, creating a window whereenqueue()seestask_running=truebut the task is about to exitprocess_loopnow continuously flushes everymax_wait_msand only exits when the queue is empty, atomically clearingtask_runningunder the pending lock to close the race windowTest plan
🤖 Generated with Claude Code