Skip to content

Commit

Permalink
Merge pull request #6988 from taskcluster/matt-boris/genericWorkerGra…
Browse files Browse the repository at this point in the history
…cefulTerminationRaceFix

fix(generic-worker): check for graceful termination before claiming work
  • Loading branch information
matt-boris committed Apr 27, 2024
2 parents fa46160 + 656df78 commit a84ce33
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions changelog/issue-6987.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
audience: users
level: patch
reference: issue 6987
---
Generic Worker now checks if a graceful termination was requested from worker runner _before_ calling `queue.claimWork()`.

This helps fix a race condition where a preemption occurs right after Generic Worker starts up, but before the graceful termination handler to abort the task has been initialized.
8 changes: 4 additions & 4 deletions workers/generic-worker/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ func RunWorker() (exitCode ExitCode) {
panic(err)
}

if graceful.TerminationRequested() {
return WORKER_SHUTDOWN
}

task := ClaimWork()

// make sure at least 5 seconds pass between tcqueue.ClaimWork API calls
Expand Down Expand Up @@ -518,10 +522,6 @@ func RunWorker() (exitCode ExitCode) {
}
}

if graceful.TerminationRequested() {
return WORKER_SHUTDOWN
}

// To avoid hammering queue, make sure there is at least 5 seconds
// between consecutive requests. Note we do this even if a task ran,
// since a task could complete in less than that amount of time.
Expand Down

0 comments on commit a84ce33

Please sign in to comment.