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.

Prisma client not attempting to reconnect on "Can't reach database server"

See original GitHub issue

Bug description

Is it possible for a prisma client to get “stuck” and not attempt to reconnect to a database server after failing to connect once?

I find that when my dev aurora serverless DB goes to sleep and a lambda fails to connect once, it seems to refuse to connect even when the DB comes back up. I have to wait for the warm lambda to go away or do a deployment before it connects again. I can reliably fix the error by changing an environment variable and waiting for the new lambda to get deployed, and it connects to the newly-awake DB fine.

"\nInvalid `prisma.user.findUnique()` invocation:\n\n\n  Can't reach database server at `platform-mish.cluster-cflui618uuxz.eu-west-1.rds.amazonaws.com`:`5432`\n\nPlease make sure your database server is running at `platform-mish.cluster-cflui618uuyz.eu-west-1.rds.amazonaws.com`:`5432`."

How to reproduce

Create a lambda function that connects to a DB. Turn the DB off, then attempt to run the lambda and connect. It will fail (as expected) with this error message.

Start the DB and then run the lambda, it will fail immediately with the same error. Change an environment variable and wait about a minute (for it to re-deploy in your VPC) and run the lambda again. It will succeed.

Expected behavior

If the client has failed to connect, it should retry connecting, maybe after a couple seconds. Consider failover scenarios as well.

Prisma information

Any query

Environment & setup

  • OS:
  • Database:
  • Node.js version:

Prisma Version

prisma                  : 3.2.1
@prisma/client          : 3.2.1
Current platform        : darwin
Query Engine (Node-API) : libquery-engine b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at ../../node_modules/@prisma/engines/libquery_engine-darwin.dylib.node)
Migration Engine        : migration-engine-cli b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at ../../node_modules/@prisma/engines/migration-engine-darwin)
Introspection Engine    : introspection-core b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at ../../node_modules/@prisma/engines/introspection-engine-darwin)
Format Binary           : prisma-fmt b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c (at ../../node_modules/@prisma/engines/prisma-fmt-darwin)
Default Engines Hash    : b71d8cb16c4ddc7e3e9821f42fd09b0f82d7934c
Studio                  : 0.435.0

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:9
  • Comments:14 (10 by maintainers)

github_iconTop GitHub Comments

6reactions
garrensmithcommented, Mar 31, 2022

https://github.com/prisma/prisma/pull/12066 fixes this.

You can test it out with prisma@dev and will be out in the next release. Would be great if you had the time to test this and let us know if this is indeed fixed for you now. Thanks!

3reactions
sreutercommented, Jan 31, 2022

@janpio Apologies for the confusion. It’s the very same locally (with a normal postgres) and therefore not related to Lambda/Aurora. That just happens to be our production setup.

https://github.com/prisma/prisma/issues/9420 mentions this also independently from Lambda/Aurora.

To reproduce:

  1. Start a service with Prisma client but have database shutdown (throws ‘can’t reach database’ error as expected)
  2. Start the database and try again without restarting your service (still throws)

For some reason this does not happen if the first ever request was successful. To reproduce:

  1. Start a service with Prisma client but have database running (works fine)
  2. Shutdown database and try again (throws ‘can’t reach database’ error as expected)
  3. Restart database and try again (works fine)

I hope this makes more sense now.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - M1 Related! - Prisma: Can't reach database server at ...
The database inside the docker cannot be found by the nextjs server where I am using prisma. The prisma client can't reach the...
Read more >
Troubleshooting database outages and connection issues
Learn about the possible reasons your database might be down or not connected and what you can do to fix it.
Read more >
Connecting the Server and Database with Prisma Client
In this section, you're going to learn how to connect your GraphQL server to your database using Prisma, which provides the interface to...
Read more >
please make sure your database server is running at ...
So, in this case, connecting to localhost:5432 from the application container will try to connect to 5432 port within that container and not...
Read more >
Can't reach database server in FRA - Build debugging - Fly.io
handleRequestError (/myapp/node_modules/@prisma/client/runtime/index.js:49670:13) 2022-07-21T09:07:01Z app[4bebc390] fra [info] at ...
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