v15-0002-Do-not-hardcode-sending-PG_PROTOCOL_LATEST-in-Ne.patch
application/octet-stream
Filename: v15-0002-Do-not-hardcode-sending-PG_PROTOCOL_LATEST-in-Ne.patch
Type: application/octet-stream
Part: 0
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 v15-0002
Subject: Do not hardcode sending PG_PROTOCOL_LATEST in NegotiateProtocolVersion
| File | + | − |
|---|---|---|
| src/backend/tcop/backend_startup.c | 13 | 6 |
From cf805364cab6c53021074d09100bb1da8481a170 Mon Sep 17 00:00:00 2001 From: Jelte Fennema-Nio <postgres@jeltef.nl> Date: Wed, 14 Aug 2024 18:25:16 +0200 Subject: [PATCH v15 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 | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/backend/tcop/backend_startup.c b/src/backend/tcop/backend_startup.c index 9ad60a6dc7..2a96c81f92 100644 --- a/src/backend/tcop/backend_startup.c +++ b/src/backend/tcop/backend_startup.c @@ -690,9 +690,13 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done) /* * Set FrontendProtocol now so that ereport() knows what format to send if - * we fail during startup. + * we fail during startup. We use the protocol version requested by the + * client unless it's higher than the latest version we support. It's + * possible that error message fields might look different in newer + * protocol versions, but that's something those new clients should be + * able to deal with. */ - FrontendProtocol = proto; + FrontendProtocol = Min(proto, PG_PROTOCOL_LATEST); /* Check that the major protocol version is in range. */ if (PG_PROTOCOL_MAJOR(proto) < PG_PROTOCOL_MAJOR(PG_PROTOCOL_EARLIEST) || @@ -852,9 +856,12 @@ ProcessStartupPacket(Port *port, bool ssl_done, bool gss_done) /* * Send a NegotiateProtocolVersion to the client. This lets the client know - * that they have requested a newer minor protocol version than we are able - * to speak. We'll speak the highest version we know about; the client can, - * of course, abandon the connection if that's a problem. + * that they have either requested a newer minor protocol version than we are + * able to speak, or at least one protocol option that we don't understand, or + * possibly both. FrontendProtocol has already been set to the version + * requested by the client or the highest version we know how to speak, + * whichever is older. If the highest version that we know how to speak is too + * old for the client, it can abandon the connection. * * We also include in the response a list of protocol options we didn't * understand. This allows clients to include optional parameters that might @@ -870,7 +877,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: c8e2d422fd556292ab751392bf76f713fe9e9fc1 -- 2.34.1