Skip to content

fix(coderd/database): prevent AcquireProvisionerJob from grabbing canceled jobs#21852

Merged
mafredri merged 2 commits intomainfrom
internal-awj5
Feb 3, 2026
Merged

fix(coderd/database): prevent AcquireProvisionerJob from grabbing canceled jobs#21852
mafredri merged 2 commits intomainfrom
internal-awj5

Conversation

@mafredri
Copy link
Member

@mafredri mafredri commented Feb 2, 2026

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

…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
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test for the AcquireProvisionerJob query in the database package, making sure that it only grabs what we expect?

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).
@mafredri
Copy link
Member Author

mafredri commented Feb 3, 2026

@deansheather done, added a test that catches the issue without the fix.

@mafredri mafredri requested a review from deansheather February 3, 2026 08:29
Copy link
Member

@deansheather deansheather left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding the test!

@mafredri mafredri merged commit f75cbab into main Feb 3, 2026
26 of 27 checks passed
@mafredri mafredri deleted the internal-awj5 branch February 3, 2026 08:42
@github-actions github-actions bot locked and limited conversation to collaborators Feb 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AcquireProvisionerJob can grab canceled pending jobs

2 participants