prisma: Timed out fetching a new connection from the pool
Bug description
Recently, I experienced similar issues to those mentioned in the following issues: https://github.com/prisma/prisma/issues/7249 https://github.com/prisma/prisma/issues/9902
That is, Prisma will sporadically hang with the following errors:
- Worker nodes:
P1001 - Web server nodes:
P2024(as in title)
At first, some errors will happen but the application recovers (with increased latency). Unfortunately, some minutes later the errors come back and it’s not recoverable at that point. Here are error log timestamps to illustrate the pattern: https://i.imgur.com/wKTLBCO.png
Here are RDS logs from the time the issue happened: https://i.imgur.com/9o1TYKl.png
It makes me think that Prisma encounters an actual issue with the DB server but for some reason is not able to recover after that.
Restarting the app servers resolves the issue.
I’ll be implementing the following auto-recovery mechanism, please let me know if it looks good to you:
prisma.$on('error', (e) => {
if (
e.message.includes(`Can't reach database server`) ||
e.message.includes(
`Timed out fetching a new connection from the connection pool`,
)
)
prisma.$disconnect().catch((e) => logger.error(e));
});
How to reproduce
No reproduction as it only happened 2 times in production.
Expected behavior
No response
Prisma information
Environment & setup
MySQL 8.0.35 hosted on Multi-AZ RDS.
Prisma Version
The issue happened to me 2 times, on 21.06 (version 5.15), and on 18.07 (version 5.16.2). If we assume the issue takes up to a month to manifest, the version 5.14 could also be affected.
I’ve been using Prisma for around 2 years and these are the first time it happened. Which makes me think a regression could’ve been introduced in the code. I’ll be rolling back to 5.13 in my production environment and monitoring.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Comments: 31 (8 by maintainers)
Hey everyone! The upcoming Prisma 5.22.0 release on Tuesday, Nov 5 will include a fix for one of the reasons this problem can occur. Your case is likely to be fixed if:
Please let us know if your case is fixed so we can investigate and fix the remaining cases.
We’re still having this issue. From time to time we get a bunch of
Timed out fetching a new connection from the connection pool(P2024)prisma: 6.5.0@prisma/client: 6.5.0Encountering this too with supabase pooler.
I haven’t encountered the issue again after rolling back to 5.13. So it’s very likely the bug has been introduced in future releases.
I think the findings of @istarkov are what this issue is about. AWS RDS with multi-AZ enabled uses a proxy for seamless switching between the primary and replica. So this is somehow consistent with the findings.
We are hitting the same issue on RDS (not using Supabase).
The symptom is that we suddenly get a wall of logs with the subj error message.
We are also observing some memory issues (perhaps a leak) but are still unsure whether they are related or something on our side.
I believe this is the reason for the issue: https://github.com/prisma/prisma/issues/24844#issuecomment-2247851311
For an unknown reason, Supavisor connections are being dropped from the database but still exist between the Vercel instance and the Supavisor endpoint. As a result, Prisma cannot detect that the connection has dropped and hangs indefinitely. This is one of the reasons why
pghas a client implementation of query_timeout.I have checked supavisor and db logs
There are usual messages like
There is nothing unusual or non-standard in the SQL logs.
I haven’t tried using port 5432. The issue reproduces somewhat consistently only in our production environment, making it difficult to test.
With a direct connection in the last few hours, we experienced a single, clear Prisma timeout error, but without the hanging issue.
We are experiencing a similar issue on a regular basis. Every few hours, we encounter the following events.
On some instances, we receive the following error:
Subsequent or parallel requests to that instance then start failing with the following error and prisma info:
This happens on any Prisma invocation, suggesting that Prisma hangs when attempting to reuse a connection.
We are using Supabase connection pool with the following connection string (Transaction mode)
Timeouts are comig in a bursts, currently we are experiencing burst of enormous amount of timeouts
App is hosted on vercel.
@SanditZZ please provide more information and a reproduction. The only case that has been confirmed so far was fixed in Prisma 5.22.0 (the one that most people in this issue except the original reporter seemed to have encountered). Just writing “+1” with no context in an issue where people discussed multiple unrelated things doesn’t make it possible for us to help you.
+1 Anyone found a solution for this yet? Any suggestions would be appreciated.
I have encountered similar issue, The issue was fixed for me after updating to the latest version of Prisma ( 5.17.0 )
I haven’t yet encountered the error again so can’t speak on that.
pt., 26 lip 2024, 00:04 użytkownik jpetto @.***> napisał: