Skip to content

Fix COPY FROM STDIN over pglite-socket#1028

Open
bahoo wants to merge 1 commit into
electric-sql:mainfrom
bahoo:fix/socket-copy-from-stdin
Open

Fix COPY FROM STDIN over pglite-socket#1028
bahoo wants to merge 1 commit into
electric-sql:mainfrom
bahoo:fix/socket-copy-from-stdin

Conversation

@bahoo

@bahoo bahoo commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

COPY ... FROM STDIN is a stateful sub-protocol: the CopyData ('d') / CopyDone ('c') / CopyFail ('f') messages that follow the query must reach PGlite in the same execProtocolRawStream call as the query itself — PGlite cannot resume a copy started in a previous call. The handler previously dispatched every wire message as its own call, which desynchronized the connection mid-COPY and left buffered response bytes that corrupted the next client's startup handshake.

The handler now detects COPY ... FROM STDIN in simple-protocol queries, synthesizes the CopyInResponse the client is waiting for, buffers the copy sub-protocol messages, and submits the whole sequence as one call, stripping the duplicate CopyInResponse from PGlite's response.

Known limitations, called out in the PR: the COPY payload is buffered in memory, extended-protocol COPY is not detected, and errors from the COPY statement itself are reported after the data has been sent.

COPY ... FROM STDIN is a stateful sub-protocol: the CopyData ('d') /
CopyDone ('c') / CopyFail ('f') messages that follow the query must reach
PGlite in the same execProtocolRawStream call as the query itself —
PGlite cannot resume a copy started in a previous call. The handler
previously dispatched every wire message as its own call, which
desynchronized the connection mid-COPY and left buffered response bytes
that corrupted the next client's startup handshake.

The handler now detects COPY ... FROM STDIN in simple-protocol queries,
synthesizes the CopyInResponse the client is waiting for, buffers the
copy sub-protocol messages, and submits the whole sequence as one call,
stripping the duplicate CopyInResponse from PGlite's response.

Known limitations, called out in the PR: the COPY payload is buffered in
memory, extended-protocol COPY is not detected, and errors from the COPY
statement itself are reported after the data has been sent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@bahoo bahoo force-pushed the fix/socket-copy-from-stdin branch from 0eab42c to 814be44 Compare June 12, 2026 19:34
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