Skip to content

fix(tokio): flush instead of sync when copy_in starts - #1402

Open
datlechin wants to merge 2 commits into
rust-postgres:masterfrom
TableProApp:tablepro
Open

datlechin wants to merge 2 commits into
rust-postgres:masterfrom
TableProApp:tablepro

Conversation

@datlechin

Copy link
Copy Markdown

copy_in sends Bind, Execute, Sync, and later a second Sync with CopyDone or CopyFail. In copy-in mode the server ignores the first Sync. When it refuses the statement before copy-in mode (missing table, permission denied, a cancel while it waits on a lock, a statement that is not COPY ... FROM STDIN), it answers that Sync with ReadyForQuery, and the Sync sent with CopyFail gets a second one. The stray ReadyForQuery goes to the next request, or fails the connection with an unexpected message when none is queued.

The fix sends Flush in place of the first Sync, so the Sync sent with CopyDone or CopyFail ends the exchange in every case. Flush still makes the server send BindComplete, CopyInResponse or the error right away.

Tests, against the docker-compose server:

  • copy_in_statement_error: COPY into a missing table, then a query on the same client.
  • copy_in_not_a_copy: SELECT 1 through copy_in, then a query.
  • copy_in_dropped_before_copy_mode: the copy_in future is dropped while the COPY waits on a lock. The CopyFail still has to go out, since the server enters copy-in mode once the lock is free.

The first two fail without the fix.

Fixes #789. Same change as #1337, plus the server tests. #1398 skips the CopyFail when no CopyInResponse arrived, which fails copy_in_dropped_before_copy_mode.

A COPY the server refuses before copy-in mode (missing table, permission, a statement that is not COPY FROM STDIN) answered that Sync with ReadyForQuery, and the Sync sent with CopyFail got a second one, which left the connection out of step. The Sync sent with CopyDone or CopyFail now ends the exchange in every case.

This branch has not been deployed

No deployments
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.

copy_in shouldn't send Sync message

1 participant