Skip to content

adapter-pg will crash Node process if there is an open connection when the database shuts down #27641

Closed

Description

@barryhagan

Bug description

When using adapter-pg, the PrismaPg object internally creates a pg.Pool, but it never subscribes to the error event from this emitter.

Since this is not handled, any error emitted from the pool will crash the entire Node process unless you have also wired up a default global handler like this:

process.on('uncaughtException', (err) => {});

At a minimum this needs to do some kind of handling and logging in the adapter, but likely should allow the caller to provide a callback handler as well.

Right now without a global handler, pool errors can crash your app.

Severity

🚨 Critical: Data loss, app crash, security issue

Reproduction

  • Create a project using the driverAdapters and queryCompiler features with a postgres database.
  • In the configuration of the PrismaPg object, set idleTimeoutMillis to 0 to keep connections alive
  • Do not set a global handler for the process 'uncaughtException' event
  • Start your application and make at least on database query
  • Stop your postgres database
  • Crash

Expected vs. Actual Behavior

Expected: pg.Pool error events should be handled so they don't cause an uncaught exception from an async callback.

Actual: my application container crashed.

Frequency

Consistently reproducible

Does this occur in development or production?

Both development and production

Is this a regression?

No

Workaround

Configure a global uncaughtException handler.

process.on('uncaughtException', (err) => {});

Prisma Schema & Queries

generator client {
  provider        = "prisma-client"
  output          = "../src/prisma-generated"
  previewFeatures = ["driverAdapters", "fullTextSearchPostgres", "queryCompiler", "views"]
  moduleFormat    = "esm"
}

Prisma Config

No response

Logs & Debug Info

No response

Environment & Setup

  • OS: macOS, CentOS
  • Database: PostgreSQL
  • Node.js version: 20.19.2

Prisma Version

6.11.1

Activity

  1. added
    kind/bug
    on Jul 13, 2025
  2. added
    bug/1-unconfirmed
    on Jul 14, 2025
  3. added a commit that references this issue on Jul 23, 2025
    3a78a38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions