Next.js Discord

Discord Forum

Timed out fetching a new connection from the connection pool

Unanswered
CuriouslyCory posted this in #help-forum
Open in Discord
I have a similar problem to OP of this post:
https://nextjs-forum.com/post/1248279948876316723#message-1248279948876316723
I have a lot of Promise.all(query) batches that cause my app to exceed the pool connection limit. I'm using the suggested method for using the same db client for all queries, but it still seems to be using a unique connection per query when I use this method (I'm assuming this is by design).
Vercel creates and manages a handful of related postgres environment variables and suggests the following:
datasource db {
  provider  = "postgresql"
  url       = env("POSTGRES_PRISMA_URL")
  directUrl = env("POSTGRES_URL_NON_POOLING")
}

Using this appears to result in a 10 second timeout and 5 connection limit (according to error logs) despite having a 15 sec timeout and no connection limit defined in their env vars.
Unhandled Rejection: PrismaClientKnownRequestError: 
Invalid `prisma.collection.upsert()` invocation:


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: 5)
    at In.handleRequestError (/var/task/node_modules/@prisma/client/runtime/library.js:122:6877

As a workaround I've created a promise batching system and I set up my own DATABASE_URL environment variable with the desired connection params.

TLDR;
My questions are:
- If my database client is set up correctly, should it still be using a connection for each query?
- Is there a way to manage the connection limits in the database settings on vercel instead of managing my own string? It would be great if the interface had options that would automatically update the env var settings instead of requiring manual intervention.

0 Replies