electric-sql / electric-sql/pglite
[BUG]: Premature `ReadyForQuery`
- Dominant language
- TypeScript
- Stars
- 16k
- Forks
- 442
- Avg merge
- 20h 19m
- Merged PRs (30d)
- 7
Description
**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
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.