pgbouncer icon indicating copy to clipboard operation
pgbouncer copied to clipboard

Add support for negotiating the protocol version with the client

Open JelteF opened this issue 1 year ago • 2 comments
trafficstars

PgBouncer currently only supports protocol version 3.0. However, it was still accepting connections if the client asked for the 3.1 protocol version. This is obviously a bug, because PgBouncer likely won't support the changes introduced in 3.1 of the protocol without any code changes.

This starts sending the NegotiateProtocolVersion message when the client asks for a minor version that PgBouncer does not support. Also, instead of erroring when it receives unsupported protocol extensions parameters it will include these in this NegotiateProtocolVersion message.

For reference this is the Postgres commit introducing NegotiateProtocolVersion: https://github.com/postgres/postgres/commit/ae65f6066dc3d19a55f4fdcd3b30003c5ad8dbed

I tested this manually using this patchset that bumps the protocol version. https://www.postgresql.org/message-id/flat/CAGECzQScQ3N-Ykv2j4NDyDtrPPc3FpRoa%3DLZ-2Uj2ocA4zr%3D4Q%40mail.gmail.com#cd9e8407820d492e8f677ee6a67c21ce

JelteF avatar Jan 12 '24 10:01 JelteF

How do you test this? I'm trying to send the protocol negotiation packet while connecting with psql and it always returns this error message:

psql: error: connection to server at "127.0.0.1", port 6432 failed: expected authentication request from server, but received v

which is really weird because when I'm reading the implementation in libpq, it clearly should support v at this particular stage in the negotiation: https://github.com/postgres/postgres/blob/b0289574bdf1202248201a3143d1459bdf5727fd/src/interfaces/libpq/fe-connect.c#L3541-L3548

levkk avatar Mar 09 '24 20:03 levkk

Sounds like you're using a libpq from before bbf9c282ce92272ed7bf6771daf0f9efa209e61b

But even after that libpq will complain. Just with a more helpful message. Better handling is in my patchset here: https://www.postgresql.org/message-id/flat/CAGECzQScQ3N-Ykv2j4NDyDtrPPc3FpRoa%3DLZ-2Uj2ocA4zr%3D4Q%40mail.gmail.com#cd9e8407820d492e8f677ee6a67c21ce

JelteF avatar Mar 09 '24 21:03 JelteF