From 902b1d580e0fbd9f71a33b1816673a1f2a466a9a Mon Sep 17 00:00:00 2001 From: Chirag Aggarwal Date: Fri, 29 May 2026 10:21:55 +0530 Subject: [PATCH] Fix deployment cancel race in build worker --- .../Modules/Functions/Workers/Builds.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php index f04f7c3807..95756addce 100644 --- a/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php +++ b/src/Appwrite/Platform/Modules/Functions/Workers/Builds.php @@ -246,14 +246,18 @@ class Builds extends Action ->setParam($resourceKey, $resource->getId()) ->setParam('deploymentId', $deployment->getId()); + $deploymentId = $deployment->getId(); + $deployment = $dbForProject->getDocument('deployments', $deploymentId); + if ($deployment->isEmpty()) { + throw new \Exception('Deployment not found'); + } + if ($deployment->getAttribute('status') === 'canceled') { - $this->cancelDeployment($deployment->getId(), $dbForProject, $queueForRealtime); + $this->cancelDeployment($deploymentId, $dbForProject, $queueForRealtime); return; } - $deploymentId = $deployment->getId(); - $deployment->setAttribute('buildStartedAt', $startTime); $deployment->setAttribute('status', 'processing'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), new Document([ @@ -534,6 +538,12 @@ class Builds extends Action } /** Request the executor to build the code... */ + $deployment = $dbForProject->getDocument('deployments', $deploymentId); + if ($deployment->getAttribute('status') === 'canceled') { + $this->cancelDeployment($deploymentId, $dbForProject, $queueForRealtime); + return; + } + $deployment->setAttribute('status', 'building'); $deployment = $dbForProject->updateDocument('deployments', $deployment->getId(), new Document([ 'status' => 'building',