Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix COPY FROM and add tests #522

Merged
merged 3 commits into from
Jul 21, 2023
Merged

Fix COPY FROM and add tests #522

merged 3 commits into from
Jul 21, 2023

Conversation

drdrsh
Copy link
Collaborator

@drdrsh drdrsh commented Jul 21, 2023

COPY commands handling had a bug that manifests with high pool contention or very show idle_timeouts.

When copying data from client to a server, you first send a COPY query. Something like

COPY copy_test_table FROM STDIN CSV

You get back a CopyInResponse (G) message from the server. Client is then expected to send zero or more CopyData (d) messages to the server and end with CopyComplete (c) or CopyFailed (f) messages.

In transaction mode, PgCat allows the server connection to be released back into the pool after it gets G message from the server. In high contention situations or with very short idle timeout, the client's attempt to checkout another connection results in the client sending CopyData packets to a server connection that is not in copy mode.

This PR fixes this bug by keeping track of copy_mode and avoiding the release of the connection back into the pool if it is in copy_mode.

@drdrsh drdrsh marked this pull request as ready for review July 21, 2023 03:17
Copy link
Contributor

@levkk levkk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

@levkk levkk merged commit 2a8f365 into postgresml:main Jul 21, 2023
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.

2 participants