Skip to content

Commit

Permalink
Fewer transaction retries
Browse files Browse the repository at this point in the history
  • Loading branch information
N2D4 committed Jan 14, 2025
1 parent 0f55c18 commit 56251cc
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions apps/backend/src/prisma-client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ export async function retryTransaction<T>(fn: (...args: Parameters<Parameters<ty
return await traceSpan('Prisma transaction', async () => {
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);

Expand Down

0 comments on commit 56251cc

Please sign in to comment.