@prisma/dev: WAL polling enters aborted socket transactions (25P02) and breaks shutdown

Open
#31,043 2 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
bun, postgresql, typescript
Domain
backend, databases

Research direction

Start with the supplied reproduction archive and its README, then run bun test repro.test.ts against the published package to confirm both failures. The report points to WAL polling, the socket queue and shutdown cleanup as the affected areas; the Prisma Dev source location is not identified. Done means polling waits for client transactions, shutdown cleans up clients before draining WAL, and the tests confirm committed rows appear once while rolled-back or disconnected writes do not appear.

Written by the indexing model from the issue text.

Description

bug/1-unconfirmed kind/bug
Package and version

@prisma/[email protected] (current npm release), @electric-sql/[email protected]

What happened?

After a socket client commits a write, opens another transaction and receives an expected SQL error, internal WAL/Streams work queries the same PGlite instance while the client transaction is still aborted. It rejects with code 25P02: current transaction is aborted, commands ignored until end of transaction block. This also occurs during server.close() with an aborted client transaction and pending WAL work.

The independent reproduction has no ORM client, schema engine, application code, migrations or external database. Both cases fail on the unpatched published package and pass with the supplied downstream patches.

What did you expect to happen?

Internal WAL polling waits until the socket transaction commits, rolls back or disconnects. Shutdown disconnects/rolls back clients before draining WAL and closing PGlite. Committed rows reach Streams exactly once; rolled-back and disconnected uncommitted rows do not appear.

Minimal reproduction

Download reproduction and tested patches. The archive contains only the test, README, two manifests and exact-version patches; no application files, credentials, databases or node_modules. It is on an isolated reproduction branch, outside the socket PR.

unzip prisma-dev-wal-repro.zip
cd prisma-dev-wal-repro
bun install --ignore-scripts
bun test repro.test.ts
# unpatched: 0 passed, 2 failed with 25P02

cp package.patched.json package.json
bun install --ignore-scripts
bun test repro.test.ts
# patched: 2 passed, 0 failed (8 assertions)

The shutdown test creates a table, runs BEGIN; INSERT INTO wal_close_probe VALUES (1); COMMIT; BEGIN; SELECT 1 / 0, asserts the expected 22012 error, then calls server.close() before ending that client. The other test holds a failed transaction open while WAL polling runs, rolls it back, disconnects with another uncommitted write, and asserts that only the two committed rows appear once in Streams.

Environment

macOS arm64; reproduction runtime/package manager: Bun 1.4.4. Node 26.13.0 is installed but the Prisma reproduction was tested with Bun, not Node’s test runner. @prisma/dev 0.25.2 is the latest npm release checked for this report. Database: the embedded PGlite instance started by startPrismaDevServer, stateless, automatically assigned ports.

Additional context

Proposed source fix:

  1. Schedule internal WAL polling through the socket queue outside client transactions. db.runExclusive() alone serializes access, not transaction ownership.
  2. Dispatch subscribers after the polling work leaves the queue, avoiding reentrant queue deadlocks.
  3. Stop/disconnect clients before the final WAL poll and before closing database/Streams resources.

Companion socket source PR: https://github.com/electric-sql/electric-pglite/pull/1222 (runOutsideTransaction(), awaited handler cleanup, three regressions; 69/69 socket tests, build/typecheck/lint pass). Prisma Dev must adopt the primitive separately; the socket PR alone does not fix this consumer.

The archive provides tested patches against the exact published bundles as a reference, not generated files proposed for the ORM tree. I could not locate public source for @prisma/dev, and its published manifest declares no repository/bugs URL, so this report supplies the reproduction and fix for the appropriate owner. Please route it to the correct repository if necessary.

Validation: independent install, two failures without patches; same tests pass with only the two supplied patches. Downstream integration: 35/35 groups passed. This concerns local development/testing, not a production database.

Dominant language
TypeScript
Stars
47.8k
Forks
2.6k
Avg merge
1d 21h
Merged PRs (30d)
227

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from prisma/orm

All issues in prisma/orm

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.