v14-0002-Do-not-hardcode-sending-PG_PROTOCOL_LATEST-in-Ne.patch

application/octet-stream

Filename: v14-0002-Do-not-hardcode-sending-PG_PROTOCOL_LATEST-in-Ne.patch
Type: application/octet-stream
Part: 0
Message: Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs

Patch

Same data as JSON: GET /api/v1/attachments/:id/patch the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes. API reference →
Format: format-patch
Series: patch v14-0002
Subject: Do not hardcode sending PG_PROTOCOL_LATEST in NegotiateProtocolVersion
File+
src/backend/tcop/backend_startup.c 6 3
From 2388067e5a77b02ccd71bffab00290c28c4f1e92 Mon Sep 17 00:00:00 2001
From: Jelte Fennema-Nio <jelte.fennema@microsoft.com>
Date: Sun, 2 Jun 2024 00:49:43 -0700
Subject: [PATCH v14 2/9] Do not hardcode sending PG_PROTOCOL_LATEST in
 NegotiateProtocolVersion

To be able to update the minor protocol version in a future version this
changes the way we build NegotiateProtocolVersion to set the correct
version. The previous code would always tell the client to use the
latest version that the server supported. Currently that works fine in
practice, because the latest version is the only version. However if we
introduce a new protocol version then a client might ask for a lower
version than the latest version that we support, but at the same time
ask for a protocol parameter that we do not support. In that case we
would send back a higher protocol version in the
NegotiateProtocolVersion message than the one that the client asked for.
This fixes that, by sending back the version the client asked for in
that case.

Finally this also sets FrontendProtocol to the negotiated minor version.
---
 src/backend/tcop/backend_startup.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/backend/tcop/backend_startup.c b/src/backend/tcop/backend_startup.c
index cfa27551964..7486f80aca4 100644
--- a/src/backend/tcop/backend_startup.c
+++ b/src/backend/tcop/backend_startup.c
@@ -684,6 +684,9 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
 						PG_PROTOCOL_MAJOR(PG_PROTOCOL_LATEST),
 						PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST))));
 
+	if (proto > PG_PROTOCOL_LATEST)
+		FrontendProtocol = PG_PROTOCOL_LATEST;
+
 	/*
 	 * Now fetch parameters out of startup packet and save them into the Port
 	 * structure.
@@ -790,8 +793,8 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done)
 		 * the newest minor protocol version we do support and the names of
 		 * any unrecognized options.
 		 */
-		if (PG_PROTOCOL_MINOR(proto) > PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST) ||
-			unrecognized_protocol_options != NIL)
+		if (PG_PROTOCOL_MINOR(proto) > PG_PROTOCOL_MINOR(PG_PROTOCOL_LATEST)
+			|| unrecognized_protocol_options != NIL)
 			SendNegotiateProtocolVersion(unrecognized_protocol_options);
 	}
 
@@ -849,7 +852,7 @@ SendNegotiateProtocolVersion(List *unrecognized_protocol_options)
 	ListCell   *lc;
 
 	pq_beginmessage(&buf, PqMsg_NegotiateProtocolVersion);
-	pq_sendint32(&buf, PG_PROTOCOL_LATEST);
+	pq_sendint32(&buf, FrontendProtocol);
 	pq_sendint32(&buf, list_length(unrecognized_protocol_options));
 	foreach(lc, unrecognized_protocol_options)
 		pq_sendstring(&buf, lfirst(lc));

base-commit: f7f4e7e6fa576761f5330963cb7af686957589b4
-- 
2.34.1