Skip to content

Support globally setting or disabling interactive transaction timeout #14487

Open

Description

@casey-chow

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)

Activity

  1. janpio commented on Feb 21, 2024

    @janpio
    Contributor

    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?

  2. added this to the 5.10.0 milestone on Mar 14, 2024
  3. janpio commented on Mar 14, 2024

    @janpio
    Contributor
  4. normancarcamo commented on Apr 11, 2024

    @normancarcamo
  5. binishjoshi commented on May 12, 2024

    @binishjoshi

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

  6. casey-chow commented on Jul 1, 2024

    @casey-chow
    Author

    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?

    Sorry to be so late to respond! Yes, I think that's sufficient for my use case.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions