question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

interactiveTransactions rollback but don't error out if timeout is reached

See original GitHub issue

Bug description

When using interactive transactions, the transaction returns successfully even if the timeout was reached and internally the transaction was rolled back.

More context here https://github.com/prisma/prisma/issues/8664#issuecomment-930403241

How to reproduce

  1. Clone https://github.com/awinograd/prisma-include-clause-bug/tree/interactive-transaction-timeout (note it is a specific branch, not main branch)
  2. run yarn dev:database
  3. run prisma migrate dev
  4. run yarn dev

Expected behavior

Transaction that surpasses timeout should throw an error rather than returning the return value as if nothing has happened.

Prisma information

all included in repro example above

Environment & setup

  • OS: MacOS
  • Database: PostgresQL
  • Node.js version: 16.9.1

Prisma Version

prisma                  : 3.1.1
@prisma/client          : 3.1.1
Current platform        : darwin
Query Engine (Node-API) : libquery-engine c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt c22652b7e418506fab23052d569b85d3aec4883f (at node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : c22652b7e418506fab23052d569b85d3aec4883f
Studio                  : 0.423.0
Preview Features        : interactiveTransactions

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
garrensmithcommented, 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

1reaction
avalletecommented, Oct 26, 2021

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”.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Transactions and batch queries (Reference) - Prisma
When the application reaches the end of the function, the transaction is committed to the database. If your application encounters an error along...
Read more >
spring transaction timeout doesn't work - Stack Overflow
In my understanding, if I set the timeout, such as 10 seconds, Spring will launch a Timer when start a new transaction, if...
Read more >
When transaction timeout, rollback didn't work - JBoss.org
Hi, i got some problem with transaction timeout, hope somebody can ... But in case of it could happen again, i would like...
Read more >
Prisma 4.7.0 Release - GitClear
If your application encounters an error as the transaction is being executed, the function will throw an exception and automatically rollback ...
Read more >
prisma 3.9.0 on Node.js Yarn
New release prisma version 3.9.0 on Node.js Yarn. ... interactiveTransactions rollback but don't error out if timeout is reached ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found