Skip to content

fix(adapter-pg): destroy pg connections after transaction database errors to prevent response leaking - #30413

Open
AbhilashG12 wants to merge 1 commit into
prisma:7.9.xfrom
AbhilashG12:fix/pg-poisoned-connection
Open

AbhilashG12 wants to merge 1 commit into
prisma:7.9.xfrom
AbhilashG12:fix/pg-poisoned-connection

Conversation

@AbhilashG12

Copy link
Copy Markdown

Linked issue

Fixes #30374

Summary

This fixes a critical data-corruption vulnerability where queries on a @prisma/adapter-pg client could receive payloads belonging to other queries after a transaction database error.

Root Cause:
When a database error (e.g., duplicate key) is raised inside a transaction, the underlying TCP socket in pg goes out of sync. Currently, when the engine triggers a ROLLBACK, the PgTransaction.rollback() method calls this.client.release() with no arguments. In pg, this incorrectly signals that the connection is healthy, returning a corrupted socket to the pool. The very next query to check out that connection reads the leftover wire bytes, resulting in an Error P2023 or returning another user's data.

Solution:

  1. Introduced an isPoisoned boolean flag on PgQueryable.
  2. When performIO catches a database error, isPoisoned is flipped to true.
  3. In PgTransaction.commit() and PgTransaction.rollback(), we check this flag. If true, we pass an Error to this.client.release(err).
  4. Passing an error explicitly instructs pg.Pool to sever and destroy the poisoned TCP socket rather than returning it to the idle pool.

Testing performed

  • Added Vitest mock tests to pg.test.ts to assert client.release() receives an Error object after a failed transaction, but receives undefined after a healthy transaction.
  • pnpm --filter @prisma/adapter-pg test

Skill update

n/a — internal only

…rors to prevent response leaking

Signed-off-by: AbhilashG12 <abhilashggg15@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 25, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Advanced

Run ID: 2b50b26b-9a6b-42d9-8801-529faab2691c

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Comment @coderabbitai help to get the list of available commands.

@AbhilashG12

Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

CodeRabbit chat interactions are restricted to organization members for this repository. Ask an organization member to interact with CodeRabbit, or set chat.allow_non_org_members: true in your configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant