From 56251ccc151c0a38ab836c0226bea1448c77e168 Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Mon, 13 Jan 2025 17:05:07 -0800 Subject: [PATCH] Fewer transaction retries --- apps/backend/src/prisma-client.tsx | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/apps/backend/src/prisma-client.tsx b/apps/backend/src/prisma-client.tsx index 43b006ac1..d250388b9 100644 --- a/apps/backend/src/prisma-client.tsx +++ b/apps/backend/src/prisma-client.tsx @@ -25,15 +25,17 @@ export async function retryTransaction(fn: (...args: Parameters { const res = await Result.retry(async (attempt) => { return await traceSpan(`transaction attempt #${attempt}`, async () => { - try { - return Result.ok(await prismaClient.$transaction(fn)); - } catch (e) { - if (e instanceof Prisma.PrismaClientKnownRequestError || e instanceof Prisma.PrismaClientUnknownRequestError) { - // retry - return Result.error(e); + return await prismaClient.$transaction(async (...args) => { + try { + return Result.ok(await fn(...args)); + } catch (e) { + if (e instanceof Prisma.PrismaClientKnownRequestError || e instanceof Prisma.PrismaClientUnknownRequestError) { + // retry + return Result.error(e); + } + throw e; } - throw e; - } + }); }); }, isDev ? 1 : 3);