postgresml / pgcat

PostgreSQL pooler with sharding, load balancing and failover support.
MIT License
3.13k stars 193 forks source link

PgCat Reads Past Buffer on Error During Server Login #876

Open tneely opened 1 week ago

tneely commented 1 week ago

Describe the bug

When reading an error message from the server during login, PgCat creates an array of bytes equal to the message length - vec![0u8; len as usize].

However Postgres includes the size in the length, and we already read it from the stream, so we end up trying to read more than what's in the buffer and eventually get an UnexpectedEof when Postgres closes the connection.

https://github.com/postgresml/pgcat/blob/main/src/server.rs#L710-L712

We need to subtract 4 from the length similar to what is done for ReadyForQuery - https://github.com/postgresml/pgcat/blob/main/src/server.rs#L787

To Reproduce

  1. Configure invalid credentials
  2. Try to start and connect to PgCat
  3. Inspect the error logs and see that the auth error is missing

Expected behavior PgCat handles error messages from the server correctly during startup.

Screenshots N/A

Desktop (please complete the following information):

Additional context Add any other context about the problem here.