auditt800
auditt800
PPrisma
Created by auditt800 on 9/16/2024 in #help-and-questions
Prisma Interactive transactions not waiting on await statement
Using isolationLevel: Prisma.TransactionIsolationLevel.Serializable seems to have solved the problem. The new issue after that was Transaction failed due to a write conflict or a deadlock. Please retry your transaction I added the retry logic, but the issue didn't resolve. So I made all three createMany calls, in my code, serial and the issue was gone. Initially I was collecting promises of the three createMany calls, then resolving it using Promise.all(promises); This parallel calls seems to be causing write conflict or a deadlock. Let me know if there is a better approach to solve this. And also if the current solution is reliable Solution:
while (retries < MAX_RETRIES) {
try {
await client.$transaction(
async (tx) => {
await writeToStuff1(txn)
await writeToStuff2(txn)

await writeToStuff3_DependentOnStuff1(txn)
await writeToStuff4_DependentOnStuff2(txn)

await createManyStuff5_DependentOnStuff2(txn)
await createManyStuff6_DependentOnStuff2(txn)
await createManyStuff7_DependentOnStuff2(txn)
},
{
maxWait: 5000, // default: 2000
timeout: 10000, // default: 5000
isolationLevel: Prisma.TransactionIsolationLevel.Serializable,
}
);
break;
} catch (error: any) {
if (error.code === "P2034") {
retries++;
continue;
}
throw error;
}
}
while (retries < MAX_RETRIES) {
try {
await client.$transaction(
async (tx) => {
await writeToStuff1(txn)
await writeToStuff2(txn)

await writeToStuff3_DependentOnStuff1(txn)
await writeToStuff4_DependentOnStuff2(txn)

await createManyStuff5_DependentOnStuff2(txn)
await createManyStuff6_DependentOnStuff2(txn)
await createManyStuff7_DependentOnStuff2(txn)
},
{
maxWait: 5000, // default: 2000
timeout: 10000, // default: 5000
isolationLevel: Prisma.TransactionIsolationLevel.Serializable,
}
);
break;
} catch (error: any) {
if (error.code === "P2034") {
retries++;
continue;
}
throw error;
}
}
2 replies