fix(tasks,runners): critical runner/task requeue and finalization bugs#4013
Closed
cursor[bot] wants to merge 2 commits into
Closed
fix(tasks,runners): critical runner/task requeue and finalization bugs#4013cursor[bot] wants to merge 2 commits into
cursor[bot] wants to merge 2 commits 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>
…finalization Runner client: when applyTerminatedJobs emergency-stops a job and Run() unwinds with an error, the error path overwrote stopped with failed. Add finalizeAfterRun that respects an already-finished status. HA reconciler: when failTaskRunnerLost wins the finalize lock but the DB already has a terminal status, complete finalization instead of bailing so pool/Redis state and autorun children are not leaked. Harden offline requeue with a pre-mutation DB re-check and rollback on persist failure. 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.
Summary
Cherry-picks validated fixes for three critical correctness bugs still present on
develop. No new behavioral commits since yesterday's inspection (only CI/test skips:75c98980,ab623b13,48cb4741,fbebe1a1).Bugs fixed
1. Duplicate dispatch on
ErrAllRunnersBusyImpact: When all runners are at capacity, a task requeued via
ErrAllRunnersBusywas enqueued while still in the running set;EventTypeRequeuedwas deferred. A concurrent queue tick couldClaimAndDequeuethe same task and start a second dispatch goroutine on the sameTaskRunner.Root cause:
TaskRunner.runcalledstate.Enqueuebefore releasing running/active bookkeeping.Fix: Call
onTaskStopbefore enqueue and emitEventTypeRequeuedsynchronously (matching reconciler requeue paths).2. Runner client overwrites stopped → failed on
terminated_jobsImpact: When the server returns
terminated_jobsand emergency-stops a job,Run()unwinds with an error. The error path overwrote an already-terminalstoppedstatus withfailed, misreporting task outcome to the server.Root cause: Unconditional failure status assignment in
job_pool.goafterRun()error.Fix: Add
finalizeAfterRunthat respects an already-finished status.3. HA pool state leak in
failTaskRunnerLostImpact: In HA mode, when the reconciler wins the finalize lock but the DB already has a terminal status (e.g. runner reported success on another node), it returned early without completing finalization. Pool/Redis state (running set, claims, autorun children) leaked.
Root cause: Early return in
failTaskRunnerLostwhentsk.Task.Status.IsFinished()without callingfinalizeRemoteTaskLocked. AlsoTaskPool.finalizeRemoteTaskLockedonly checkedEnd != nilunder HA.Fix: Complete finalization when DB already finished; harden offline requeue with pre-mutation DB re-check and rollback on persist failure; release stale pool state when
Endis already set (non-HA too).Validation
go test ./services/tasks/... ./services/runners/...— all passTestTaskRunner_ErrAllRunnersBusy_ReleasesRunningBeforeEnqueue,TestRunningJob_finalizeAfterRun_*, reconciler HA finalization tests