fix(delivery): raise $transaction timeout to 30 s in enqueue (BIT-33904)
ci / rust (push) Successful in 5m26s
ci / typescript (push) Successful in 11m29s

Advisory-lock contention with 40-photo chunks from sendGalleryRest
expired the default 10 s transaction timeout (Prisma P2028). Pass an
explicit { timeout: 30_000 } so only the execution timeout is raised;
maxWait stays at the global 10 s default for pool acquisition.

Paperclip: BIT-33904
This commit is contained in:
paula-alves committed 2026-12-04 07:47:35 +00:00
1 parent 2ec4f263b6
commit 465937212c
2 files changed
+61 -1

No files matched your search

+1 -1
View File
@@ -288,7 +288,7 @@ export class DeliveryService {
);
}
return created;
});
}, { timeout: 30_000 });
queued.push(...items);
}
for (const item of queued) this.deps.broadcaster.library(item.organizationId, { type: "delivery.updated", item: toItemSummary(item) });
@@ -0,0 +1,60 @@
import { describe, expect, it } from "vitest";
import { DeliveryService } from "./service.js";
import type { Db } from "../db.js";
/** A minimal hand-rolled Db whose `$transaction` spy captures the options argument. */
function mockDb(captured: { options: unknown }): Pick<Db, "$transaction"> & Record<string, unknown> {
const tx = {
$executeRaw: (strings: TemplateStringsArray) => Promise.resolve(strings.length),
deliveryItem: {
aggregate: async () => ({ _max: { sequence: null } }),
create: async ({ data }: { data: Record<string, unknown> }) => ({
id: "item-1",
targetId: data.targetId,
photoId: data.photoId,
eventId: data.eventId,
sequence: data.sequence,
status: "QUEUED",
attempts: 0,
lastError: null,
remotePath: null,
byteSize: null,
updatedAt: new Date(),
organizationId: data.organizationId,
}),
},
};
return {
$transaction: async (fn: (tx: typeof tx) => Promise<unknown>, options?: unknown) => {
captured.options = options;
return fn(tx);
},
deliveryTarget: { findFirst: async () => ({ id: "t1", colorLabel: null, copyTargetId: null }) },
photo: { findMany: async () => [{ id: "p1", organizationId: "org", status: "READY", eventId: "ev1" }] },
deliveryItem: { findMany: async () => [] },
} as unknown as Pick<Db, "$transaction"> & Record<string, unknown>;
}
describe("DeliveryService.enqueue transaction timeout (BIT-33904)", () => {
it("passes a 30 s execution timeout to $transaction so advisory-lock contention doesn't hit P2028", async () => {
const captured: { options: unknown } = { options: undefined };
const db = mockDb(captured) as unknown as Db;
const delivery = new DeliveryService({
db,
storage: {} as never,
secrets: undefined,
broadcaster: { library: () => {}, broadcast: () => {} } as never,
log: { info: () => {}, warn: () => {} } as never,
});
await delivery.enqueue({
organizationId: "org",
targetId: "t1",
photoIds: ["p1"],
again: false,
requestedById: null,
});
expect(captured.options).toEqual({ timeout: 30_000 });
});
});