question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Timed out fetching a new connection, even with high connection_limit

See original GitHub issue

Bug description

When I kick off many queries concurrently, I get this issue:

Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 1, connection limit: 100)

I expect to NOT get this issue

How to reproduce

async function example() {
  const prisma = getPrisma('some_url?connection_limit=100&pool_timeout=1');

  const range = [...Array(10).keys()];
  await Promise.all(range.map(async (val) => {
    await prisma.nft.findMany({take: 10});
  }));

  console.log("done!");
}

When I run this code, I get this error:

Timed out fetching a new connection from the connection pool. More info: http://pris.ly/d/connection-pool (Current connection pool timeout: 1, connection limit: 100)

However, based on the Prisma docs, it seems like I should not be running into this.

If there are no idle connections available in the connection pool, the query engine opens additional database connections and adds them to the connection pool until the number of database connections reaches the limit defined by connection_limit.

Since my connection_limit (100) is much higher than the number of queries I’m kicking off (10), I don’t get why I’m running into this issue.

Also, my DB supports a maximum of over 3000 connections

One more note: weirdly, if I use connection_limit=1, I get no errors

Expected behavior

I expect all my queries to execute successfully

Prisma information

Not needed

Environment & setup

  • OS: Mac OS
  • Database: PostgreSQL
  • Node.js version: 16.7.0

Prisma Version

prisma                  : 3.8.1
@prisma/client          : 3.8.1
Current platform        : darwin
Query Engine (Node-API) : libquery-engine 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f (at ../../node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : 34df67547cf5598f5a6cd3eb45f14ee70c3fb86f
Studio                  : 0.452.0
Preview Features        : interactiveTransactions

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:4
  • Comments:13 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
normandeaupcommented, Oct 22, 2022

@janpio I’m having the same issue on https://kirka.io

My PostgreSQL database allows 1000 connections and with those Prisma options: connection_limit=800&pool_timeout=10, I’m randomly getting about once every 15 minutes, Timed out fetching a new connection from the connection pool. before Prisma reaches the 800 connections limit, if I understand correctly, Prisma would need to use all the connections available (800) before sending the Timeout error?

image

My database logs also show that everything is fine, and the api server isn’t lagging.

Version: 3.15.0 (I tried multiple versions of prisma 3)

I can provide any information needed, this issue has been annoying me for a couple days now, let me know if you need me to test anything particular.

Thank you

0reactions
janpiocommented, Nov 25, 2022

Closing then until someone provides more information. Please comment or open a new issue. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Timed out fetching a new connection from the pool · Issue #7249
Bug description After running my application for around 1-2 days, I start getting the following error: prisma:client Error: Timed out fetching a new ......
Read more >
Timed out fetching a new connection from the connection pool ...
I have a nestjs scheduler which will run every one hour. I'm using multiple library to connect to postgres ...
Read more >
Connection management (Guide) - Prisma
Opening a new connection takes time and can slow down your application if you ... a high connection_limit can quickly exhaust the database...
Read more >
Using Prisma to Address Connection Pooling Issues in ...
In addition to being a great aid to development, the Prisma Data ... For example, you can reduce the connection timeout for inactive ......
Read more >
Admin settings - Queries | Looker - Google Cloud
Looker will automatically stop a query that is still running when you ... are allowed per connection, and queued queries are timed out...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found