From 2edf5a08aef668d07b00fd73691b4c180953f5bf Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 21 Feb 2025 19:57:44 +0100 Subject: [PATCH] job check one last time for completed job before returning 404 --- backend/windmill-api/src/jobs.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/windmill-api/src/jobs.rs b/backend/windmill-api/src/jobs.rs index b5e1bc5a08..b86dae1ed0 100644 --- a/backend/windmill-api/src/jobs.rs +++ b/backend/windmill-api/src/jobs.rs @@ -915,7 +915,16 @@ impl<'a> GetQuery<'a> { .fetch_queued(db, job_id, workspace_id) .await? .map(Job::QueuedJob); - not_found_if_none(job_maybe, "Job", job_id.to_string()) + // potential race condition here, if the job was in queue and completed right after the fetch completed, so we need to check one last time + if let Some(job) = job_maybe { + return Ok(job); + } else { + let cjob2 = self + .fetch_completed(db, job_id, workspace_id) + .await? + .map(Job::CompletedJob); + not_found_if_none(cjob2, "Job", job_id.to_string()) + } } } }