any suggestions about what to do with this error? ...
# prisma-client

Question

How to handle the 'Transaction API error: Transaction already closed: Transaction is no longer valid. Last state: 'Expired'' error in Prisma? Can increasing timeouts help? How can I gracefully recover from this error? Can I get more information about what's going on? Is there a global configuration to increase timeouts for transactions?

Answer

The issue causing the error might be related to a bug in Prisma. It is advised to create a new issue on Github and include details of the error. Increasing timeouts might help in some cases, but it is not a guaranteed solution. To gracefully recover from this error, it is possible to use `prisma.c.$disconnect()` in a catch block, which would close all existing connections with the database and allow the client to automatically connect to the database by opening a new connection on the subsequent request. In order to get more information about what is going on, it is recommended to use the recently shipped Prisma metrics, which can provide information about how many active connections Prisma holds and other relevant details. If the error only occurs when the database is located far away, then increasing timeouts might be the only solution as there isn't a global configuration to increase timeouts for transactions. It is important to note that this error can be intermittent and may not occur consistently.

m
any suggestions about what to do with this error? "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 load
Copy code
{
      maxWait: 20000, // default: 2000
      timeout: 60000, // default: 5000
    }
{"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","clientVersion":"3.14.0"}
👀 1
1
n
Are you getting these errors every time, or do they happen intermittently?
m
intermittently
any advice?
n
I think you are running into the error mentioned in this issue: https://github.com/prisma/prisma/issues/11565 The issue suggests that this must be fixed in the latest release. but it seems that’s not the case. Could you perhaps create a new issue for this?
m
ok
could my timeout be too low?
what should I do in my code to gracefully recover from this error? I added a
prisma.c.$disconnect()
in a catch() block but I have no idea if that's correct or useful
n
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
m
ok
this error is really causing me a lot of difficulty
any ideas how can I get more information about what's going on?
i
I also have the same error. ( on 3.15 ) In my case, there are no other options to keep transaction. Increasing timeouts works, but still, it's strange.
m
дякую
n
You might want to have a look at metrics which we recently shipped, it should help in figuring out how many active connections does prisma hold and other relevant information.
👍 1
i
In my case, it only happens when the database located somewhere far away, and this issue appears. There is no such issues when the apl and db are located in same network/cluster. Increasing timeout for only case when i need to connect to the remote database doesn't look like solution, since it happens only in this case. Also didn't found any global configuration that allows me to increase timeouts for transactions. But going for every place, and settings timeouts, seems strange to me
490 Views