Prisma connection doesn't recover from idle in transaction state
See original GitHub issueBug description
Hi there,
As the title mention it, I encountered a bug when using both interactives and non-interactives transactions with prisma.
Sometimes, the prisma client get stuck into a ‘idle in transaction’ mode, this mainly happens under loads (eg: truncate all tables in a database) when postgres is allowed little ressources (eg: in CI, 1 CPU for postgres container).
From my preliminary investigation:
- This bug is random and ressources related (with 4 CPU allowed to postgres it doesn’t appears), with less query load it doesn’t appears. And when it does, it doesn’t appears at the same point.
- It seems to be postgres “lock” related. For us, this show up during our “integrations testing” in which we truncate all the tables, then seed them with controlled data. Sometimes it’s one of the “flush” (TRUNCATE) query who get stuck in the ‘idle in transaction’ mode, sometimes it’s one of the “seed” (INSERT INTO). The common denominator seems to be the fact that some locks aren’t unlocked by postgres.
The main issue is that, once it get into this state, the prisma client never get out of it. In our case, requiring to restart the webserver to instantiate a new connection to the database.
It’s not very clear for me how to make a MRE from my issue since it’s heavily related our code and only appears under loads.
How to reproduce
Here is a MRE reproducing this issue: https://github.com/avallete/prisma-9584-MRE
Expected behavior
Prisma could throw a “transaction timeout” error after X seconds passed in a transaction which doesn’t end.
Prisma information
nothing specific
Environment & setup
- OS: OSX/Debian
- Database: postgres:12
- Node.js version: v14.17.1
Prisma Version
prisma : 2.30.3
@prisma/client : 2.30.3
Current platform : darwin
Query Engine (Binary) : query-engine b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at ../../node_modules/@prisma/engines/query-engine-darwin)
Migration Engine : migration-engine-cli b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at ../../node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine : introspection-core b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at ../../node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary : prisma-fmt b8c35d44de987a9691890b3ddf3e2e7effb9bf20 (at ../../node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash : b8c35d44de987a9691890b3ddf3e2e7effb9bf20
Studio : 0.423.0
Preview Features : interactiveTransactions, nApi, referentialActions
Also tried with the latest 3.X version, the issue is the same.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:16
- Comments:9 (3 by maintainers)
Hi. I will add my bits to it.
I am facing a similar problem in MySql 8. This works locally (or at least I didn’t encounter the problem yet) on 4-core 32GB device but hangs (promise do not return) in i.e. preemptible GCE server with 1 core and low amount of RAM. Seems like the database is not locked afterwards just the Prisma promise does not return, nor throw/rejects.
In my scenario that prevents ack’ing broker messages at some point which creates the service unresponsive (15 is its prefetch/concurrent limit):
Code:
output: 15 lines of pending promise output each 2 seconds indefinitely
Changing from interactive to array-based transaction method does not change the outcome.
Creating my own timeout over this to prevent it, seems like overkill and it should be rather taken care of by the framework. It would not fix the problem though just prevent zombie service.
Prisma:
@janpio The issue in my MRE is resolved as of 3.9.x! Thanks