{"record":{"id":"03b55dac3e87a692","repo":"Dokploy/dokploy","slug":"bad-request-03b55d","errorCode":"BAD_REQUEST","errorMessage":"Deployment is not running","messagePattern":"Deployment is not running","errorType":"exception","errorClass":"TRPCError","httpStatus":400,"severity":"warning","filePath":"apps/dokploy/server/api/routers/deployment.ts","lineNumber":186,"sourceCode":"\t\t.mutation(async ({ input, ctx }) => {\n\t\t\tconst deployment = await findDeploymentById(input.deploymentId);\n\t\t\tconst serviceId = deployment.applicationId || deployment.composeId;\n\t\t\tif (serviceId) {\n\t\t\t\tawait checkServicePermissionAndAccess(ctx, serviceId, {\n\t\t\t\t\tdeployment: [\"cancel\"],\n\t\t\t\t});\n\t\t\t} else if (deployment.schedule?.serverId) {\n\t\t\t\tconst targetServer = await findServerById(deployment.schedule.serverId);\n\t\t\t\tif (targetServer.organizationId !== ctx.session.activeOrganizationId) {\n\t\t\t\t\tthrow new TRPCError({\n\t\t\t\t\t\tcode: \"UNAUTHORIZED\",\n\t\t\t\t\t\tmessage: \"You don't have access to this deployment.\",\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif (!deployment.pid) {\n\t\t\t\tthrow new TRPCError({\n\t\t\t\t\tcode: \"BAD_REQUEST\",\n\t\t\t\t\tmessage: \"Deployment is not running\",\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tconst command = `kill -9 ${deployment.pid}`;\n\t\t\tif (deployment.schedule?.serverId) {\n\t\t\t\tawait execAsyncRemote(deployment.schedule.serverId, command);\n\t\t\t} else {\n\t\t\t\tawait execAsync(command);\n\t\t\t}\n\n\t\t\tawait updateDeploymentStatus(deployment.deploymentId, \"error\");\n\t\t\tawait audit(ctx, {\n\t\t\t\taction: \"cancel\",\n\t\t\t\tresourceType: \"deployment\",\n\t\t\t\tresourceId: deployment.deploymentId,\n\t\t\t});","sourceCodeStart":168,"sourceCodeEnd":204,"githubUrl":"https://github.com/Dokploy/dokploy/blob/546686ea3587f12ec5652217dedd9f7960fb6d15/apps/dokploy/server/api/routers/deployment.ts#L168-L204","documentation":"Guard before killing a deployment process: if deployment.pid is null the deployment is not running, so there is nothing to cancel and the request fails with BAD_REQUEST.","triggerScenarios":"Cancelling a deployment that has already completed, failed, or never started (pid never recorded or cleared after finish).","commonSituations":"Race between UI 'Cancel' click and deployment finishing; polling latency showing a stale running state.","solutions":["Refresh deployment status before attempting cancel","Treat this error as benign if the deployment just finished","Only show Cancel when status is running and pid exists"],"exampleFix":"// before\nif (deployment.status === 'running') await cancel(deploymentId);\n// after\nif (deployment.status === 'running' && deployment.pid) await cancel(deploymentId);","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"const isCancellable = (d: {pid: number | null; status: string}) => d.status === 'running' && !!d.pid;","tryCatchPattern":"if (!isCancellable(deployment)) return; // nothing running\nawait cancel(deploymentId);","preventionTips":["Poll status before showing Cancel","Treat already-finished deployments as a no-op"],"tags":["dokploy","deployment","cancel","state"],"backgroundTag":"invalid-state-transition","analyzedSha":"546686ea3587f12ec5652217dedd9f7960fb6d15","analyzedAt":"2026-08-27T05:18:58.095Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}