prisma: Inappropriate Connection Pool Timeout Error
Bug description
Hi, we are running into an issue with Prisma and postgres with the following error -
Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 10, connection limit: 1)
This is occurring in an AWS lambda instance. We have already read and implemented the appropriate changes based on this documentation https://www.prisma.io/docs/guides/performance-and-optimization/connection-management#serverless-environments-faas by ensuring that we set the connection limit to 1 (as seen in the error above) and instantiating the client outside of the lambda invocation. However, this issue persists in about 1/1000 queries to the db.
I have also confirmed that we are no where near hitting our connection limit on the postgres side when this error occurs, so I am led to believe that there is something happening on the prisma side rather than on the db side.
It seems that we are getting this error within a fraction of a second of the request starting, which means that it is not waiting the full 10 seconds before throwing.
I think this is a bug in the query engine. The error is happening here https://github.com/prisma/prisma-engines/blob/main/query-engine/connectors/sql-query-connector/src/database/postgresql.rs#L71 which calls out to https://github.com/prisma/quaint/blob/main/src/pooled.rs#L479-L504
I believe that under some race condition, mobc is incorrectly throwing a timeout error which is then caught, but we’re not seeing the actual error message, because it is overridden here - https://github.com/prisma/prisma-engines/blob/main/libs/user-facing-errors/src/query_engine/mod.rs#L239
When I set pool_timeout to 0, we don’t see this error anymore.
Right now we have just switched to setting pool_timeout to 0 as a workaround, but it does seem like there is a bug going on on Prisma’s end.
How to reproduce
Use prisma in a Lambda with serverless-express.
Prisma will transiently fail.
Expected behavior
We should get a better error description than pool timeout to be able to identify the underlying issue.
Prisma information
Any arbitrary query that runs first on lambda invocation.
Environment & setup
AWS Lambda with Postgres
Prisma Version
4.15.0
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 2
- Comments: 19 (5 by maintainers)
@why-el We are currently at 5.4.2
Yes sir I am trying, but it’s fighting me very hard. It happens extremely infrequently, but as you can imagine, it happens in the production application which affects our users.
Then please definitely open a new issue, provide as much information as possible - optimally a reproduction app on GitHub - and also fill all the information the bug report issue template asks for, because we understand that to even be able to think on what could be going wrong. Thanks.
It will wait for the
connection pool timeout, which by default (and in your app) is 10 seconds. You can increase that limit to a really high number for Prisma to wait forever by usingpool_timeout(https://www.prisma.io/docs/concepts/components/prisma-client/working-with-prismaclient/connection-pool#setting-the-connection-pool-timeout), but of course your throughput will then still be limited by those 9 connections that Prisma can only use at a time, and the queries will wait a long time.Increasing the pool size / connection limit is definitely the better approach.