Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prisma does not recover from PrismaClientInitializationError #9420

Closed
MichalLytek opened this issue Sep 24, 2021 · 6 comments
Closed

Prisma does not recover from PrismaClientInitializationError #9420

MichalLytek opened this issue Sep 24, 2021 · 6 comments
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: connect topic: connection pool topic: postgresql
Milestone

Comments

@MichalLytek
Copy link

Bug description

When the database is not available on startup, calling prisma.$connect() throw PrismaClientInitializationError.

However, when the database becomes available, all the repetive calls of prisma.$connect() or normal Prisma Client queries fails with the same PrismaClientInitializationError.

How to reproduce

  1. Turn off your database server (e.g. disconnect from VPN).
  2. Start the Node app which calls prisma.$connect() every e.g. 10 seconds.
  3. See it throws PrismaClientInitializationError
  4. Turn on your database server (e.g. connect to VPN).
  5. The Node app is still running in the background.
  6. See it still throws PrismaClientInitializationError.
  7. Restart the app and see it can now easily connect to the database.

Expected behavior

It should try to reconnect instead of throwing PrismaClientInitializationError when the database becomes available.

Prisma information

Environment & setup

  • OS: Ubuntu 20.04
  • Database: Postgres
  • Node.js version: v16.9.1

Prisma Version

prisma                  : 3.0.2
@prisma/client          : 3.0.2
Current platform        : debian-openssl-1.1.x
Query Engine (Node-API) : libquery-engine 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
Migration Engine        : migration-engine-cli 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x)
Introspection Engine    : introspection-core 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x)
Format Binary           : prisma-fmt 2452cc6313d52b8b9a96999ac0e974d0aedf88db (at node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x)
Default Engines Hash    : 2452cc6313d52b8b9a96999ac0e974d0aedf88db
Studio                  : 0.423.0
@MichalLytek MichalLytek added the kind/bug A reported bug. label Sep 24, 2021
@MichalLytek
Copy link
Author

MichalLytek commented Sep 24, 2021

When I drop the connection in runtime, it throws PrismaClientKnownRequestError with P1001 but when I reestablish the connection, it gets back to working properly without any issues 😉

So the issue is only about the first connection attempt.

@janpio janpio added team/client Issue for team Client. bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Sep 24, 2021
@pantharshit00 pantharshit00 added bug/2-confirmed Bug has been reproduced and confirmed. and removed bug/1-unconfirmed Bug should have enough information for reproduction, but confirmation has not happened yet. labels Sep 28, 2021
@timgriffin89
Copy link

Hi folks, we're experiencing this issue too. Is there any update on this bug? Is there a way to work around it in the meantime (other than restarting the application)?

@s-montigny-desautels
Copy link

Hi, we are experiencing this issue too. For now, we are creating a new instance of PrismaClient when having an error on the first connect. I don't know if it's the best solution, but it solve our problem for now.

let prisma = new PrismaClient();

const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));

(async () => {
  while (true) {
    try {
      await prisma.$connect();
      break;
    } catch {
      await sleep(1000);
      prisma = new PrismaClient();
    }
  }
})();

@Miladiir
Copy link

I am also experiencing this error. Additionally no error is logged when used with new PrismaClient({ log: [{ emit: "stdout", level: "error" }] ]).

@garrensmith
Copy link
Contributor

garrensmith commented Mar 31, 2022

#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!

@janpio janpio added this to the 3.12.0 milestone Mar 31, 2022
@AndrewSouthpaw
Copy link
Contributor

AndrewSouthpaw commented May 11, 2023

This appears to have regressed at least in >= 4.10.0:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/2-confirmed Bug has been reproduced and confirmed. kind/bug A reported bug. team/client Issue for team Client. topic: connect topic: connection pool topic: postgresql
Projects
None yet
Development

No branches or pull requests

8 participants