From 465937212cd752d7ea4e25e45b5adcdc8df19fa7 Mon Sep 17 00:00:00 2001 From: paula-alves Date: Fri, 4 Dec 2026 07:47:35 +0000 Subject: [PATCH] fix(delivery): raise $transaction timeout to 30 s in enqueue (BIT-33904) 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 --- apps/api/src/delivery/service.ts | 2 +- .../src/delivery/transaction-timeout.test.ts | 60 +++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 apps/api/src/delivery/transaction-timeout.test.ts diff --git a/apps/api/src/delivery/service.ts b/apps/api/src/delivery/service.ts index 00b9366..3262b4d 100644 --- a/apps/api/src/delivery/service.ts +++ b/apps/api/src/delivery/service.ts @@ -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) }); diff --git a/apps/api/src/delivery/transaction-timeout.test.ts b/apps/api/src/delivery/transaction-timeout.test.ts new file mode 100644 index 0000000..4f2309e --- /dev/null +++ b/apps/api/src/delivery/transaction-timeout.test.ts @@ -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 & Record { + const tx = { + $executeRaw: (strings: TemplateStringsArray) => Promise.resolve(strings.length), + deliveryItem: { + aggregate: async () => ({ _max: { sequence: null } }), + create: async ({ data }: { data: Record }) => ({ + 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, 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 & Record; +} + +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 }); + }); +});