-
Notifications
You must be signed in to change notification settings - Fork 22
Fix bug in handling postgres COPY command and a few others
#610
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
Merged
Conversation
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
Overview
Packages and Vulnerabilities (23 package changes and 0 vulnerability changes)
Changes for packages of type
|
| Package | Versionghcr.io/gatewayd-io/gatewayd:15c3ad0 |
Versiongatewaydio/gatewayd:latest |
|
|---|---|---|---|
| ➖ | ca-certificates | 20240705-r0 |
|
| ➖ | openssl | 3.3.2-r0 |
|
| ➖ | pax-utils | 1.3.7-r2 |
Changes for packages of type golang (20 changes)
| Package | Versionghcr.io/gatewayd-io/gatewayd:15c3ad0 |
Versiongatewaydio/gatewayd:latest |
|
|---|---|---|---|
| ♾️ | github.com/cyphar/filepath-securejoin | 0.3.2 |
0.3.1 |
| ♾️ | github.com/docker/docker | 27.3.1+incompatible |
27.2.1+incompatible |
| ♾️ | github.com/gatewayd-io/gatewayd | (devel) |
0.9.7 |
| ♾️ | github.com/gatewayd-io/gatewayd-plugin-sdk | 0.3.2 |
0.3.1 |
| ♾️ | github.com/getsentry/sentry-go | 0.29.0 |
0.28.1 |
| ♾️ | github.com/hashicorp/yamux | 0.1.2 |
0.1.1 |
| ➕ | github.com/imdario/mergo | 0.3.16 |
|
| ♾️ | github.com/jackc/pgx/v5 | 5.7.1 |
5.7.0 |
| ♾️ | github.com/klauspost/compress | 1.17.10 |
1.17.9 |
| ♾️ | github.com/prometheus/client_golang | 1.20.4 |
1.20.3 |
| ♾️ | go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp | 0.55.0 |
0.54.0 |
| ♾️ | go.opentelemetry.io/otel | 1.30.0 |
1.29.0 |
| ♾️ | go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc | 1.30.0 |
1.29.0 |
| ♾️ | go.opentelemetry.io/otel/metric | 1.30.0 |
1.29.0 |
| ♾️ | go.opentelemetry.io/otel/sdk | 1.30.0 |
1.29.0 |
| ♾️ | go.opentelemetry.io/otel/trace | 1.30.0 |
1.29.0 |
| ♾️ | golang.org/x/exp | 0.0.0-20240909161429-701f63a606c0 |
0.0.0-20240904232852-e7e105dedf7e |
| ♾️ | google.golang.org/genproto/googleapis/rpc | 0.0.0-20240924160255-9d4c2d233b61 |
0.0.0-20240903143218-8af14fe29dc1 |
| ♾️ | google.golang.org/grpc | 1.67.0 |
1.66.0 |
| ♾️ | stdlib | go1.23.1 |
1.23.1 |
COPY commandCOPY command and a few others
sinadarbouy
reviewed
Sep 29, 2024
sinadarbouy
reviewed
Sep 29, 2024
sinadarbouy
approved these changes
Sep 29, 2024
Collaborator
sinadarbouy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM🎉 Great catch and fix
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.
Ticket(s)
Closes #533.
Description
After hours of debugging, I discovered that the issue stemmed from a few incorrect assumptions. The first was that the chunk size read from the connection should be compared to the
ReceiveChunkSize, rather than the total amount of data received up to that point. The second assumption was that receiving zero data from the server should automatically close the connection, which has since been resolved.The third assumption was that every request to PostgreSQL would elicit an immediate response, but the behavior of the
COPYcommand proved otherwise. When a client issues aCOPYcommand to the server, PostgreSQL replies with aCopyInResponse. If no errors occur, the client begins sendingCopyDatamessages, which may consist of multiple requests, depending on the chunk size. After eachCopyDatamessage, however, the server does not send an acknowledgment or response—it simply waits. Only when the client sends aCopyDonemessage at the end of the data transmission does the server reply withCommandCompleteandReadyForQuerymessages. This means the client can send multiple requests without receiving an immediate response for each one. The finalReadyForQueryresponse from the server signals that the client can proceed with the next request.Ref: https://www.postgresql.org/docs/current/protocol-message-formats.html
In order to make sure that it works as expected, I tested the referenced SQL dump file in the issue and it works like a charm. I tested GatewayD with
pgbenchand found out that concurrent reads and writes to theServer.connectionToProxyMapcauses fatal errors, hence exiting the process. I changed the type tosync.Mapto avoid this in the future and make GatewayD more stable. Note that thetpsbefore and after the change is decreased and the latency is increased, which is expected:Before:
After:
Direct connection to database (without using GatewayD):
Surprisingly GatewayD performs better when running the benchmark, which is due to the warm up when booting up. GatewayD creates 100 connections to postgres and puts them in the queue, which in turn causes 100 master processes to be created in postgres, hence speeding up transactions by more than 24%, while decreasing the latency average by almost 20%.
CC @sh-soltanpour
Related PRs
N/A
Development Checklist
make gen-docscommand.Legal Checklist