Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support globally setting or disabling interactive transaction timeout #14487

Open
casey-chow opened this issue Jul 26, 2022 · 4 comments
Open

Comments

@casey-chow
Copy link

casey-chow commented Jul 26, 2022

Problem

I often need to debug transactions in Postgres in development, but in interactive transactions, pausing at a breakpoint for more than 5 seconds leads the transaction to rollback so I can't watch the request continue. I'd like to be able to disable the timeout in debug so I can observe this behavior better.

Suggested solution

Add an interactive transaction timeout setting to the PrismaClient constructor that sets the timeout globally. This would allow me to set up my own debug logic as needed.

Alternatives

Create a facade function for interactive transactions that sets this for me. This is of course a bandaid solution.

Context

#8664 (comment)

@janpio
Copy link
Member

janpio commented Feb 21, 2024

The recent release 5.10.x added support for global transactionOptions:

Configure transaction options in the PrismaClient constructor

This feature enables you to configure the following transaction options on a global level via the PrismaClient constructor:

  • isolationLevel: Sets the transaction isolation level. By default, this is set to the value currently configured in your database.
  • timeout: The maximum amount of time the interactive transaction can run before being canceled and rolled back. The default value is 5 seconds.
  • maxWait: The maximum amount of time Prisma Client will wait to acquire a transaction from the database. The default value is 2 seconds.

Here is an example of how you can set this value globally for all transactions:

const prisma = new PrismaClient({
  transactionOptions: {
    isolationLevel: 'ReadCommitted',
    timeout: 1_000, // 1 sec
    maxWait: 2_000  // 2 sec
  }
})

Thanks a lot to our fantastic community member @tockn, who took the initiative to implement this feature in Prisma ORM 🎉

Note that you can still override the global values by setting them on a particular transaction.

Does this satisfy your need @casey-chow?

@janpio janpio added this to the 5.10.0 milestone Mar 14, 2024
@janpio
Copy link
Member

janpio commented Mar 14, 2024

Ping @casey-chow

@normancarcamo

This comment was marked as outdated.

@cyclonejet
Copy link

@casey-chow is asking for something to disable the timeout. Something like manual transaction rollback and committing: #15211 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants