Skip to content

Commit 531698c

Browse files
committed
more deadlock detection
1 parent 1144d7e commit 531698c

File tree

6 files changed

+675
-31
lines changed

6 files changed

+675
-31
lines changed

apps/webapp/app/runEngine/concerns/runChainStates.server.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,10 @@ export class DefaultRunChainStateManager implements RunChainStateManager {
204204
parentQueue,
205205
});
206206

207-
if (typeof parentQueue?.concurrencyLimit === "undefined") {
207+
if (
208+
typeof parentQueue?.concurrencyLimit === "undefined" ||
209+
parentQueue.concurrencyLimit === null
210+
) {
208211
return true;
209212
}
210213

apps/webapp/app/runEngine/services/triggerTask.server.ts

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
import { RunDuplicateIdempotencyKeyError, RunEngine } from "@internal/run-engine";
1+
import {
2+
RunDuplicateIdempotencyKeyError,
3+
RunEngine,
4+
RunOneTimeUseTokenError,
5+
} from "@internal/run-engine";
26
import { Tracer } from "@opentelemetry/api";
7+
import { tryCatch } from "@trigger.dev/core/utils";
38
import {
49
TaskRunError,
510
taskRunErrorEnhancer,
611
taskRunErrorToString,
712
TriggerTaskRequestBody,
813
} from "@trigger.dev/core/v3";
914
import { RunId, stringifyDuration } from "@trigger.dev/core/v3/isomorphic";
10-
import { Prisma, PrismaClientOrTransaction } from "@trigger.dev/database";
15+
import { PrismaClientOrTransaction } from "@trigger.dev/database";
1116
import { createTags } from "~/models/taskRunTag.server";
1217
import { AuthenticatedEnvironment } from "~/services/apiAuth.server";
1318
import { logger } from "~/services/logger.server";
@@ -122,7 +127,11 @@ export class RunEngineTriggerTaskService {
122127
throw entitlementValidation.error;
123128
}
124129

125-
const delayUntil = await parseDelay(body.options?.delay);
130+
const [parseDelayError, delayUntil] = await tryCatch(parseDelay(body.options?.delay));
131+
132+
if (parseDelayError) {
133+
throw new EngineServiceValidationError(`Invalid delay ${body.options?.delay}`);
134+
}
126135

127136
const ttl =
128137
typeof body.options?.ttl === "number"
@@ -324,32 +333,10 @@ export class RunEngineTriggerTaskService {
324333
return await this.call({ taskId, environment, body, options, attempt: attempt + 1 });
325334
}
326335

327-
// Detect a prisma transaction Unique constraint violation
328-
if (error instanceof Prisma.PrismaClientKnownRequestError) {
329-
logger.debug("TriggerTask: Prisma transaction error", {
330-
code: error.code,
331-
message: error.message,
332-
meta: error.meta,
333-
});
334-
335-
if (error.code === "P2002") {
336-
const target = error.meta?.target;
337-
338-
if (
339-
Array.isArray(target) &&
340-
target.length > 0 &&
341-
typeof target[0] === "string" &&
342-
target[0].includes("oneTimeUseToken")
343-
) {
344-
throw new EngineServiceValidationError(
345-
`Cannot trigger ${taskId} with a one-time use token as it has already been used.`
346-
);
347-
} else {
348-
throw new EngineServiceValidationError(
349-
`Cannot trigger ${taskId} as it has already been triggered with the same idempotency key.`
350-
);
351-
}
352-
}
336+
if (error instanceof RunOneTimeUseTokenError) {
337+
throw new EngineServiceValidationError(
338+
`Cannot trigger ${taskId} with a one-time use token as it has already been used.`
339+
);
353340
}
354341

355342
throw error;

0 commit comments

Comments
 (0)