This is a common error when using a Prisma transaction with slightly heavy data. There is a default timeout for the Prisma transaction, but you can custom-set the timeout to suit your case, as shown below. The issue is happening because the time needed for the transaction is taking more time than the default time.

Update the transaction as follow:

    await this.prisma.$transaction(
  async (db) => {
    const caseFile = await this.findOneByLeadId(leadIdentifier);

    if (caseFile) {
      const { caseIdentifier } = caseFile;

      const update = { ...caseFile, notes };
      await db.case_file.update({
        where: { case_file_guid: caseIdentifier },
        data: {
          note_text: notes,
        },
      });

      await createNotesAction(db, caseIdentifier);
    } else {
      throw new Error("Case file not found");
    }
  },
  {
    maxWait: 5000, // 5 seconds max wait to connect to prisma
    timeout: 20000, // 20 seconds
  }
);
Answer from Moath Thawahreh on Stack Overflow
🌐
GitHub
github.com › prisma › prisma › issues › 13713
Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired' P2028 · Issue #13713 · prisma/prisma
June 8, 2022 - Bug description "Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired'." I'm using 3.14.0 I increased timeouts and these queries generally take ~500ms though they can take longer under l...
Author   prisma
Discussions

Transaction API error: Transaction already closed
Transaction API error: Transaction already closed: A commit cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 5408 ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the ... More on answeroverflow.com
🌐 answeroverflow.com
June 13, 2025
node.js - Prisma transaction - Stack Overflow
I'm trying to upsert and then from that result I have to go throw an array and upsert the values from another table model ProductVariant { id Int @id @default(autoincrem... More on stackoverflow.com
🌐 stackoverflow.com
August 28, 2023
Interactive Transaction API timing out after upgrading from 4.7.0 and above
After upgrading from Prisma version 4.4.0 to version 4.9.0, the Interactive Transaction API consistently times out for the same code that previously worked without issue. This issue appears to be s... More on github.com
🌐 github.com
7
March 20, 2023
prisma - How to use $transaction API in this scenario? - Stack Overflow
Since an error happened, prisma.$transaction was never called, so a inserted into the database. More on stackoverflow.com
🌐 stackoverflow.com
🌐
DEV Community
dev.to › reyronald › dealing-with-open-database-transactions-in-prisma-3clk
Dealing with open database transactions in Prisma - DEV Community
February 23, 2025 - PrismaClientKnownRequestError: Transaction API error: Transaction already closed: A commit cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 5012 ms passed since the start of the transaction.
🌐
Answer Overflow
answeroverflow.com › m › 1383022673692725281
Transaction API error: Transaction already closed - Prisma
June 13, 2025 - Transaction API error: Transaction already closed: A commit cannot be executed on an expired transaction. The timeout for this transaction was 5000 ms, however 5408 ms passed since the start of the transaction. Consider increasing the interactive transaction timeout or doing less work in the ...
Find elsewhere
🌐
GitClear
gitclear.com › open_repos › prisma › prisma › release › 4.7.0
Prisma 4.7.0 Release - GitClear
December 21, 2022 - RangeError: Invalid count value during npx prisma generate with DEBUG=* on integration build · When rejectOnNotFound is used, chaining deeper into a related table still throws if it doesn't find anything ... Transaction API error: Transaction already closed: Transaction is no longer valid.
🌐
Stack Overflow
stackoverflow.com › questions › 76995011 › prisma-transaction
node.js - Prisma transaction - Stack Overflow
August 28, 2023 - and its giving me the following error message "Transaction already closed: Could not perform operation." does anyone know how can i fix this error or another way to make it
🌐
Fixdevs
fixdevs.com › home › blog › fix: prisma transaction error — transaction already closed or rolled back
Fix: Prisma Transaction Error — Transaction Already Closed or Rolled Back - FixDevs
May 22, 2026 - The timeout error (Unable to start ... A “Transaction already closed” error means your code tried to use the transaction after it was already committed or rolled back....
🌐
GitHub
github.com › prisma › prisma › issues › 18393
Interactive Transaction API timing out after upgrading from 4.7.0 and above · Issue #18393 · prisma/prisma
March 20, 2023 - Transaction API error: Transaction already closed: Could not perform operation. at Zr.handleRequestError (----project-path---\node_modules\@prisma\client\runtime\library.js:171:6414) at Zr.handleAndLogRequestError (----project-path---\node_modules\@prisma\client\runtime\library.js:171:5948) at Zr.request (----project-path---\node_modules\@prisma\client\runtime\library.js:171:5786) at async t._request (----project-path---\node_modules\@prisma\client\runtime\library.js:174:10455) at async Promise.all (index 0) at async prisma.$transaction.maxWait (----project-path---\scripts\seeder.ts:1162:21) at async Proxy._transactionWithCallback (----project-path---\node_modules\@prisma\client\runtime\library.js:174:9384) { code: 'P2028', clientVersion: '4.11.0', meta: { error: 'Transaction already closed: Could not perform operation.'
Author   prisma
🌐
Linen
linen.dev › s › prisma › t › 2337063 › in-my-case-it-only-happens-when-the-database-located-somewhe
any suggestions about what to do with this error Transaction Prisma #prisma-client
I think disconnect should work as it would close all existing connections with database, and on the subsequent request prisma client should automatically connect to the database by opening a new connection ... I also have the same error. ( on 3.15 ) In my case, there are no other options to keep transaction.
🌐
Prisma
prisma.io › home › transactions and batch queries › transactions and batch queries › transactions and batch queries › transactions and batch queries
Transactions and batch queries (Reference) | Prisma Documentation
Additionally, increment the // version when we perform this update so all other clients trying // to book this same seat will have an outdated version. const seats = await client.seat.updateMany({ data: { claimedBy: userEmail, version: { increment: 1, }, }, where: { id: availableSeat.id, version: availableSeat.version, // This version field is the key; only claim seat if in-memory version matches database version, indicating that the field has not been updated }, }); if (seats.count === 0) { throw new Error(`That seat is already booked! Please try again.`); } It is now impossible for two peopl
🌐
YouTube
youtube.com › watch
Resolving the Transaction already closed Error in Prisma with for...of Loops - YouTube
Learn how to effectively manage Prisma transactions by replacing `forEach` with `for...of` loops to avoid `Transaction already closed` errors.---This video i...
Published   April 7, 2025
Views   17
🌐
GitHub
github.com › prisma › prisma › issues › 26199
prisma transaction timeout crashes process when entity create is included in traversal cb · Issue #26199 · prisma/prisma
January 29, 2025 - Consider increasing the interactive ... { modelName: 'SomeEntity', error: 'Transaction already closed: A batch query cannot be executed on an expired transaction....
Author   prisma
🌐
DEV Community
dev.to › this-is-learning › its-prisma-time-transactions-ji5
It's Prisma Time - Transactions - DEV Community
February 16, 2023 - In this moment, Prisma handles the transactions in two ways, the first one is the official feature and the second one is in preview. Let's start from the first one. The first method to do a transaction in Prisma is using the $transaction method. This method accepts a list of operations that are performed in a single transaction.
🌐
GitHub
github.com › prisma › prisma › discussions › 26807
How to Set a Query Execution Timeout in Prisma? · prisma/prisma · Discussion #26807
Prisma's interactive transactions have a default timeout of 5 seconds, which is what you're encountering in your error message. When a transaction times out, Prisma will roll it back, but it doesn't automatically cancel any in progress queries.
Author   prisma
🌐
Teable Community
community.teable.ai › teable discussions
Prisma limit blocking full export of base - Teable Discussions - Teable Community
April 10, 2026 - ❌ Base exported failed: Invalid `prisma.attachmentsTable.findMany()` invocation: Transaction API error: Transaction already closed: A query cannot be executed on an expired transaction.