fix(tasks): prevent duplicate dispatch on all-runners-busy requeue#3988
Draft
cursor[bot] wants to merge 1 commit into
Draft
fix(tasks): prevent duplicate dispatch on all-runners-busy requeue#3988cursor[bot] wants to merge 1 commit into
cursor[bot] wants to merge 1 commit into
Conversation
When every runner is at capacity, ErrAllRunnersBusy requeued tasks by enqueueing them while they still sat in the running set, then sending EventTypeRequeued from a defer. A periodic queue tick could ClaimAndDequeue the task in that window and start a second dispatch on the same TaskRunner. Release running/active bookkeeping before enqueueing and notify the pool synchronously, matching the reconciler requeue paths. Co-authored-by: Denis Gukov <fiftin@outlook.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.
Bug and impact
When all remote runners are busy, a task is requeued via
ErrAllRunnersBusy. The old path enqueued the task while it still remained in the pool's running set, and only sentEventTypeRequeuedfrom adeferafterrun()returned.A periodic queue tick (
EventTypeEmpty, every 5s) or any other queue event could run in that window,ClaimAndDequeuethe task, and start a second dispatch on the sameTaskRunner. That can cause duplicate runner assignments, corrupted pool state, and duplicate task execution.Root cause
TaskRunner.run()usedEnqueue()immediately but deferredEventTypeRequeued(which callsonTaskStop()). The reconciler'srequeueTaskRunnerOffline()already documented the correct pattern but only sent the event synchronously — it still enqueued before releasing running state.Fix
onTaskStop()beforeEnqueue()so the task is never simultaneously queued and running.EventTypeRequeuedsynchronously (not fromdefer) so the current queue pass skips an immediate retry.Validation
TestTaskRunner_ErrAllRunnersBusy_ReleasesRunningBeforeEnqueueTestTaskPool_RequeuedEventCleansRunningStateAndSkipsImmediateRetryand reconciler requeue tests pass