You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
interactiveTransactions rollback but don't error out if timeout is reached #9533
When using interactive transactions, the transaction returns successfully even if the timeout was reached and internally the transaction was rolled back.
Can this affect regular (non-interactive) transactions as well? We have enabled interactiveTransactions in our client for one specific call (which is very unlikely to time out, though), but we're currently investigating an issue very similar to this one, where a prisma.$transaction([...]) call does not throw or log any errors, but the supposedly created data is not present in the database afterwards. Replacing prisma.$transaction([...]) with Promise.all([...]) solved this (and fortunately for us, we don't really need transactions in this context).
Edit: upon second glance, I thought my question might be a bit vague, so let me rephrase it:
With respect to this issue, is there a difference between prisma.$transaction([...]) and prisma.$transaction(async (prisma) => {...}) or are both variants affected by the issue if interactiveTransactions is enabled?
Can this affect regular (non-interactive) transactions as well? We have enabled interactiveTransactions in our client for one specific call (which is very unlikely to time out, though), but we're currently investigating an issue very similar to this one, where a prisma.$transaction([...]) call does not throw or log any errors, but the supposedly created data is not present in the database afterwards. Replacing prisma.$transaction([...]) with Promise.all([...]) solved this (and fortunately for us, we don't really need transactions in this context).
Edit: upon second glance, I thought my question might be a bit vague, so let me rephrase it: With respect to this issue, is there a difference between prisma.$transaction([...]) and prisma.$transaction(async (prisma) => {...}) or are both variants affected by the issue if interactiveTransactions is enabled?
I think this issue is related to another one I opened here: #9584
If the root cause is indeed the same (issue in transaction timeout handling), it should affect regular transactions as well, since in my issue I made an MRE reproducing the error with "regular transactions".
The query-engine will never throw an actual error but will return an error object:
{
"is_panic":false,
"message":"Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired'.",
"meta":{
"error":"Transaction already closed: Transaction is no longer valid. Last state: 'Expired'."
},
"error_code":"P2028"
}
We need to check the response and throw an error if we detect it. We need to do the same for rollback
Reacted by Cedric Kring, Andrew Valleteau, ViZhe, pierre and Matt Mueller
I think I've also run into this issue. When I turn on interactiveTransactions preview feature, a long-running transaction invoked the old way (prisma.$transaction([...])) suddenly starts failing with this error:
[0] prisma:info Starting a sqlite pool with 9 connections.
[0] PrismaClientKnownRequestError:
[0] Invalid `prisma_1.prisma.contract.create()` invocation in
[0] /home/livthomas/Projects/livthomas/pawnshop-next/build/main/legacy/contract/importLegacyContractRecords.js:15:41
[0]
[0] 12 const userPasswordsMap = await (0, createUserHashedPasswordsMap_1.createUserHashedPasswordsMap)(userNames);
[0] 13 const operations = results.map(result => {
[0] 14 const data = (0, convertLegacyRecordToContract_1.convertLegacyRecordToContract)(result, userPasswordsMap, archived);
[0] → 15 return prisma_1.prisma.contract.create(
[0] Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired'.
[0] at Object.request (/home/livthomas/Projects/livthomas/pawnshop-next/node_modules/@prisma/client/runtime/index.js:39054:15)
[0] at async Promise.all (index 0)
[0] at async PrismaClient._transactionWithCallback (/home/livthomas/Projects/livthomas/pawnshop-next/node_modules/@prisma/client/runtime/index.js:39655:18)
[0] at async importLegacyContractRecords (/home/livthomas/Projects/livthomas/pawnshop-next/build/main/legacy/contract/importLegacyContractRecords.js:17:5)
[0] at async reportLegacyTableImportStatus (/home/livthomas/Projects/livthomas/pawnshop-next/build/main/legacy/reportLegacyTableImportStatus.js:34:9)
[0] at async importLegacyDatabase (/home/livthomas/Projects/livthomas/pawnshop-next/build/main/legacy/importLegacyDatabase.js:27:20)
[0] at async electron/js2c/browser_init.js:197:563 {
[0] code: 'P2028',
[0] clientVersion: '3.8.0',
[0] meta: {
[0] error: "Transaction already closed: Transaction is no longer valid. Last state: 'Expired'."
[0] }
[0] }
This transaction works without any problems when this preview feature is disabled and its execution usually takes around 30 seconds.
Activity
pantharshit00 commentedon Oct 2, 2021
I can reproduce this. Thanks for the detailed report.
Gerrit-K commentedon Oct 26, 2021
Can this affect regular (non-interactive) transactions as well? We have enabled
interactiveTransactionsin our client for one specific call (which is very unlikely to time out, though), but we're currently investigating an issue very similar to this one, where aprisma.$transaction([...])call does not throw or log any errors, but the supposedly created data is not present in the database afterwards. Replacingprisma.$transaction([...])withPromise.all([...])solved this (and fortunately for us, we don't really need transactions in this context).Edit: upon second glance, I thought my question might be a bit vague, so let me rephrase it:
With respect to this issue, is there a difference between
prisma.$transaction([...])andprisma.$transaction(async (prisma) => {...})or are both variants affected by the issue ifinteractiveTransactionsis enabled?avallete commentedon Oct 26, 2021
I think this issue is related to another one I opened here: #9584
If the root cause is indeed the same (issue in transaction timeout handling), it should affect regular transactions as well, since in my issue I made an MRE reproducing the error with "regular transactions".
garrensmith commentedon Jan 5, 2022
From what I can see on this. The issue is here https://github.com/prisma/prisma/blob/ec0a0182bd81f82b70d1a12a48bd7a523300a5b9/packages/engine-core/src/library/LibraryEngine.ts#L120
The query-engine will never throw an actual error but will return an error object:
{ "is_panic":false, "message":"Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired'.", "meta":{ "error":"Transaction already closed: Transaction is no longer valid. Last state: 'Expired'." }, "error_code":"P2028" }We need to check the response and throw an error if we detect it. We need to do the same for rollback
matthewmueller commentedon Jan 11, 2022
PR ready for review here: #10797
livthomas commentedon Jan 18, 2022
I think I've also run into this issue. When I turn on
interactiveTransactionspreview feature, a long-running transaction invoked the old way (prisma.$transaction([...])) suddenly starts failing with this error:This transaction works without any problems when this preview feature is disabled and its execution usually takes around 30 seconds.
I'm using SQLite database.