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

Make transaction timeouts configurable _globally_ when calling new PrismaClient() #15028

Closed
capaj opened this issue Aug 26, 2022 · 6 comments
Closed
Labels

Comments

@capaj
Copy link

capaj commented Aug 26, 2022

Problem

the default interactive transaction timeout is too low.
For example I work on a DB located on the other side of the world. With the default timeout it easily get's closed even when nothing goes wrong.

Suggested solution

  1. increase the default timeout to 10s and 20s like
{
  maxWait: 10000,
  timeout: 20000
}
  1. allow users to override this for prisma client instance like this:
new PrismaClient({
   transactionTimeouts: {
     maxWait: 10000,
     timeout: 20000
  }
})

Alternatives

create a helper function something like this:

// helper, because the default prisma transaction timeouts are too small
export const prismaTransaction = <R>(fn: (prisma: Prisma.TransactionClient) => Promise<R>) => {
  return prismaClient.$transaction(fn, {
    timeout: 30000,
    maxWait: 60000
  })
}

Additional context

#13713

@felipdc
Copy link

felipdc commented Sep 2, 2022

We need this ASAP!

@primemb
Copy link

primemb commented Jun 14, 2023

any update ?

@janpio janpio changed the title Feature request: make transaction timeouts configurable globally when calling new PrismaClient() Make transaction timeouts configurable _globally_ when calling new PrismaClient() Jun 14, 2023
@michaelhays
Copy link

#19592 adds this, and just needs tests/approval to be merged.

@divmgl
Copy link

divmgl commented Feb 9, 2024

Hi, just ran into this now. We have hundreds of transactions in our app and having to go hunt them down as they fail is very time consuming. Looking forward to this improvement, ty.

@janpio
Copy link
Member

janpio commented Feb 21, 2024

This has been shipped as part of release 5.10.x:

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.

@janpio janpio closed this as completed Feb 21, 2024
@calebpitan
Copy link

This is the luckiest I've been with running into any issue on Prisma: 'cause this issue had been open for almost two years, but luckily for me, when it mattered to me, alas (!), it was just resolved two weeks ago. Trust me, I've been unlucky with an awful lot, long lasting issues from like 3, 4 years all still open.

I celebrate this likkle win 🎉🥳

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

No branches or pull requests

8 participants