Re: libpq compression

From: Daniil Zakhlystov <usernamedt(at)yandex-team(dot)ru>
To: pgsql-hackers(at)lists(dot)postgresql(dot)org
Cc: Konstantin Knizhnik <knizhnik(at)garret(dot)ru>
Subject: Re: libpq compression
Date: 2020-10-28 15:09:40
Message-ID: 160389778089.1204.10960019875914983324.pgcf@coridan.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

The following review has been posted through the commitfest application:
make installcheck-world: not tested
Implements feature: not tested
Spec compliant: not tested
Documentation: not tested

Hi, thanks for the patch!

I’ve made a quick review and found one issue.

If the backend sends a CompressionAck message followed by some already compressed message (for example, AuthenticationOk), then there is a chance that pqReadData() will read both messages into the read buffer at once. In this case, the CompressionAck message will be read normally, but the client will fail to recognize the next message (for example, AuthenticationOk) since it came in a compressed form but was incorrectly read as a regular message. So the client would not be able to recognize the second message and will crash.

Example of a successful launch (added some debug output):
usernamedt-osx: ~ usernamedt $ psql -d "host = x.x.x.x port = 6432 dbname = testdb user = testuser compression = 1"
NUM_READ: 6 (pqReadData read CompressionAck (6 bytes) and nothing more)
pqReadData RC: 1
NUM_READ: 346
pqReadData RC: 1
psql (14devel)
Type "help" for help.

testdb => // OK

Example of a failed launch:
usernamedt-osx: ~ usernamedt $ psql -d "host = x.x.x.x port = 6432 dbname = testdb user = testuser compression = 1"
NUM_READ: 24 (pqReadData read CompressionAck (6 bytes) and compressed AuthenticationOk (18 bytes) came after it)
pqReadData RC: 1
psql: error: could not connect to server: expected authentication request from server, but received x // FAIL

--
Daniil Zakhlystov

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Fujii Masao 2020-10-28 15:16:22 Re: Add Information during standby recovery conflicts
Previous Message Julien Rouhaud 2020-10-28 14:35:15 Re: cutting down the TODO list thread