Skip to content

[BUG]: Premature ReadyForQuery #958

@Tobbe

Description

@Tobbe

Describe the bug

PGlite processes wire-protocol messages one at a time. When a Parse message fails, PGlite emits ErrorResponse + ReadyForQuery immediately — before the client's Sync arrives. Standard PostgreSQL only emits ReadyForQuery in response to Sync. This gave Prisma's schema engine two ReadyForQuery messages where it expected one, desynchronising its message pipeline and producing P1017.

To Reproduce

https://github.com/Tobbe/repro-pglite-p1017

See the README in that repo for exact reproduction steps

Logs
If applicable, include logs (ideally as text, not screenshots) that you gathered.

Details

  • PGlite version: 0.4.2
  • using any extensions? which ones?: No
  • OS version: macOS 15.2
  • node, bun, deno or browser version: Node 24.14.1

Additional context

The bug was identified by Claude Sonnet 4.6.
The reproduction was generated by MiMo V2 Pro Free. It took me and the LLM three iterations to arrive at an (imo) acceptable repro.

I had Sonnet arrive at the bug twice, in totally separate apps with no prior knowledge of the issue.
The second time it gave this explanation:

Now I fully understand the bug. Here's what's happening:

  1. The schema engine sends Parse + Describe + Sync as a batch in 196 bytes
  2. pglite-socket splits them and sends each message one at a time to execProtocolRawStream
  3. PGlite processes Parse alone → returns ErrorResponse + ReadyForQuery (it generates ReadyForQuery immediately, which is wrong — in the real PG protocol, ReadyForQuery only comes from a Sync)
  4. PGlite processes Describe → returns 0 bytes (nothing to describe for a failed parse, but no error/NoData sent)
  5. PGlite processes Sync → returns another ReadyForQuery

The schema engine's tokio-postgres receives an extra unexpected ReadyForQuery and its protocol state machine gets corrupted, which surfaces later as P1017.

Other

The reproduction repo also has a "fix"/workaround that might be helpful

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions