Repository navigation
Conversation
Add copy_in_initial_message_has_no_sync test that asserts copy_in's initial Bind+Execute message contains no Sync (and includes a Flush). This test FAILS because encode_copy_in currently delegates to query::encode which appends a Sync. CopyInReceiver also sends Sync with CopyDone/CopyFail, so the server receives two Syncs and may reply with two ReadyForQuery messages, crashing the connection. https://claude.ai/code/session_017Lx8faWtxGJDiU2rbqGeHm
Add encode_no_sync() that sends Bind+Execute+Flush instead of Bind+Execute+Sync. Wire encode_copy_in() to use it. This fixes the double-Sync crash: copy_in no longer sends Sync in the initial message, so CopyInReceiver's Sync with CopyDone/CopyFail is the only one — exactly one ReadyForQuery per COPY cycle. The Flush message forces the server to deliver buffered output without producing ReadyForQuery, which prevents a hang when the server rejects the COPY before entering COPY mode (error path). https://claude.ai/code/session_017Lx8faWtxGJDiU2rbqGeHm
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
(another problem I encountered with while working on https://github.com/NikolayS/rpg)
Bug
copy_in()callsquery::encode()which sends Bind+Execute+Sync. ThenCopyInReceiversends another Sync with CopyDone/CopyFail. Two Syncs produce twoReadyForQuerymessages. The second arrives when the connection driver's response queue is empty, crashing with "unexpected message from server".We encountered this in rpg when running PostgreSQL's
copy2regression test — multi-statement COPY sequences would crash the connection.Why PostgreSQL masks this in the success path: PG explicitly ignores Sync during COPY-IN mode (protocol spec §55.2.6). So for successful COPYs the extra Sync is silently dropped. But if the server rejects the COPY before entering COPY mode (e.g. table dropped between prepare and execute), the Sync is processed normally → double ReadyForQuery → crash. Non-PG wire-compatible servers may not ignore Sync during COPY mode at all, making the success path crash too.
Fix
Replace Sync with Flush (
'H') in the initial Bind+Execute message:Red/green TDD
Commit history demonstrates the fix:
5e003fe): addscopy_in_initial_message_has_no_synctest — fails becauseencode_copy_indelegates toquery::encode(includes Sync, no Flush)c1055b4): addsencode_no_sync(Bind+Execute+Flush), wiresencode_copy_into use it — test passes