From f9217eca57109a4f9c7b338d1ded9fbe1ca062a0 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio Date: Tue, 2 Jan 2024 11:19:54 +0100 Subject: [PATCH v13 7/9] Bump protocol version to 3.2 In preparation of new additions to the protocol in a follow up commit this bumps the minor protocol version number. Instead of bumping the version number to 3.1, which would be the next minor version, we skip that one and bump straight to 3.2. The reason for this is that many PgBouncer releases have, due to an off-by-one bug, reported 3.1 as supported[1]. These versions would interpret 3.1 as equivalent to 3.0. So if we would now add extra messages to the 3.1 protocol, clients would succeed to connect to PgBouncer, but would then cause connection failures when sending such new messages. So instead of bumping to 3.1, we bump the protocol version to 3.2, for which these buggy PgBouncer releases will correctly close the connection at the startup packet. It's a bit strange to skip a version number due to a bug in a third-party application, but PgBouncer is used widely enough that it seems worth it to not cause user confusion when connecting to recent versions of it. Especially since skipping a single minor version number in the protocol versioning doesn't really cost us anything. So, while this is not the most theoretically sound decission, it is the most pragmatic one. [1]: https://github.com/pgbouncer/pgbouncer/pull/1007 --- doc/src/sgml/libpq.sgml | 5 +++-- src/include/libpq/pqcomm.h | 3 +-- src/interfaces/libpq/fe-connect.c | 8 ++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc/src/sgml/libpq.sgml b/doc/src/sgml/libpq.sgml index f02f8b64eb1..1d31e56daac 100644 --- a/doc/src/sgml/libpq.sgml +++ b/doc/src/sgml/libpq.sgml @@ -2326,10 +2326,11 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname The current supported values are - 3.0 + 3.0, + 3.2, and latest. The latest value is equivalent to the latest protocol version that is supported by the used - libpq version, which currently is 3.0, but this will + libpq version, which currently is 3.2, but this will change in future libpq releases. diff --git a/src/include/libpq/pqcomm.h b/src/include/libpq/pqcomm.h index 6925f10602b..b93bc14f109 100644 --- a/src/include/libpq/pqcomm.h +++ b/src/include/libpq/pqcomm.h @@ -91,11 +91,10 @@ is_unixsock_path(const char *path) /* * The earliest and latest frontend/backend protocol version supported. - * (Only protocol version 3 is currently supported) */ #define PG_PROTOCOL_EARLIEST PG_PROTOCOL(3,0) -#define PG_PROTOCOL_LATEST PG_PROTOCOL(3,0) +#define PG_PROTOCOL_LATEST PG_PROTOCOL(3,2) typedef uint32 ProtocolVersion; /* FE/BE protocol version number */ diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 694becbdc4c..cc144479d62 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -1845,6 +1845,14 @@ pqConnectOptions2(PGconn *conn) { conn->max_pversion = PG_PROTOCOL_LATEST; } + else if (strcmp(conn->max_protocol_version, "3.1") == 0) + { + conn->status = CONNECTION_BAD; + libpq_append_conn_error(conn, "invalid %s value: \"%s\"", + "max_protocol_version", + conn->max_protocol_version); + return false; + } else { char *end; -- 2.34.1