fix(coderd/database): prevent AcquireProvisionerJob from grabbing canceled jobs#21852
Merged
fix(coderd/database): prevent AcquireProvisionerJob from grabbing canceled jobs#21852
Conversation
…celed jobs The AcquireProvisionerJob query only checked started_at IS NULL, allowing it to acquire jobs that were canceled while pending (which have completed_at set but started_at still NULL). Added completed_at IS NULL check to the query to prevent this. Also fixed JobCompleteBuilder.Do() in dbfake to set started_at when completing jobs, ensuring test provisioner daemons don't attempt to acquire already-completed fake jobs. Fixes coder/internal#1323
deansheather
reviewed
Feb 2, 2026
Member
deansheather
left a comment
There was a problem hiding this comment.
Can you add a test for the AcquireProvisionerJob query in the database package, making sure that it only grabs what we expect?
940f81f to
c87110f
Compare
Adds a test case to TestAcquireProvisionerJob that verifies the query correctly skips jobs that were canceled while pending (started_at is NULL but completed_at is set).
c87110f to
c3e7274
Compare
Member
Author
|
@deansheather done, added a test that catches the issue without the fix. |
deansheather
approved these changes
Feb 3, 2026
Member
deansheather
left a comment
There was a problem hiding this comment.
Thanks for adding the test!
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
The
AcquireProvisionerJobquery only checkedstarted_at IS NULL, allowing it to acquire jobs that were canceled while pending (which havecompleted_atset butstarted_atstill NULL).Added
completed_at IS NULLcheck to the query to prevent this.Also fixed
JobCompleteBuilder.Do()in dbfake to setstarted_atwhen completing jobs, ensuring test provisioner daemons don't attempt to acquire already-completed fake jobs.Fixes coder/internal#1323