Skip to content

Commit 6221282

Browse files
committed
better checking if an error is an abort error
1 parent 4ce1066 commit 6221282

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

internal-packages/run-engine/src/batch-queue/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
CallbackFairQueueKeyProducer,
1414
WorkerQueueManager,
1515
BatchedSpanManager,
16+
isAbortError,
1617
type FairQueueOptions,
1718
type StoredMessage,
1819
} from "@trigger.dev/redis-worker";
@@ -663,7 +664,7 @@ export class BatchQueue {
663664
}
664665
}
665666
} catch (error) {
666-
if (error instanceof Error && error.name === "AbortError") {
667+
if (isAbortError(error)) {
667668
this.logger.debug("Worker queue consumer aborted", { loopId });
668669
this.batchedSpanManager.cleanup(loopId);
669670
return;

packages/redis-worker/src/fair-queue/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { type z } from "zod";
77
import { ConcurrencyManager } from "./concurrency.js";
88
import { MasterQueue } from "./masterQueue.js";
99
import { type RetryStrategy, ExponentialBackoffRetry } from "./retry.js";
10+
import { isAbortError } from "../utils.js";
1011
import {
1112
FairQueueTelemetry,
1213
FairQueueAttributes,
@@ -769,7 +770,7 @@ export class FairQueue<TPayloadSchema extends z.ZodTypeAny = z.ZodUnknown> {
769770
});
770771
}
771772
} catch (error) {
772-
if (error instanceof Error && error.message === "AbortError") {
773+
if (isAbortError(error)) {
773774
this.logger.debug("Master queue consumer aborted", { loopId });
774775
this.batchedSpanManager.cleanup(loopId);
775776
return;
@@ -1330,7 +1331,7 @@ export class FairQueue<TPayloadSchema extends z.ZodTypeAny = z.ZodUnknown> {
13301331
}
13311332
}
13321333
} catch (error) {
1333-
if (error instanceof Error && error.name === "AbortError") {
1334+
if (isAbortError(error)) {
13341335
this.logger.debug("Reclaim loop aborted");
13351336
return;
13361337
}

packages/redis-worker/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./queue.js";
22
export * from "./worker.js";
3+
export * from "./utils.js";
34

45
// Fair Queue System
56
export * from "./fair-queue/index.js";

packages/redis-worker/src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* Check if an error is an AbortError.
3+
*
4+
* This handles both:
5+
* - Custom abort errors created with `new Error("AbortError")` (sets .message)
6+
* - Native Node.js AbortError from timers/promises (sets .name)
7+
*/
8+
export function isAbortError(error: unknown): boolean {
9+
return (
10+
error instanceof Error && (error.name === "AbortError" || error.message === "AbortError")
11+
);
12+
}

0 commit comments

Comments
 (0)