pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: libpq: Extend "read pending" check from SSL to GSS
Date: Tue, 07 Jul 2026 15:56:46 +0000
Message-ID: <E1wh8AA-00019v-1Y@gemulon.postgresql.org> (raw)

libpq: Extend "read pending" check from SSL to GSS

An extra check for pending bytes in the SSL layer has been part of
pqReadReady() for a very long time (79ff2e96d). But when GSS transport
encryption was added, it didn't receive the same treatment. (As
79ff2e96d notes, "The bug that I fixed in this patch is exceptionally
hard to reproduce reliably.")

Without that check, it's possible to hit a hang in gssencmode, if the
server splits a large libpq message such that the final message in a
streamed response is part of the same wrapped token as the split
message:

    DataRowDataRowDataRowDataRowDataRowData
    -- token boundary --
    RowDataRowCommandCompleteReadyForQuery

If the split message takes up enough memory to nearly fill libpq's
receive buffer, libpq may return from pqReadData() before the later
messages are pulled out of the PqGSSRecvBuffer. Without additional
socket activity from the server, pqReadReady() (via pqSocketCheck())
will never again return true, hanging the connection.

Pull the pending-bytes check into the pqsecure API layer, where both
SSL and GSS now implement it.

Note that this does not fix the root problem! Third party clients of
libpq have no way to call pqsecure_read_is_pending() in their own
polling. This just brings the GSS implementation up to par with the
existing SSL workaround; a broader fix is left to a subsequent commit.

In preparation for the broader fix, this patch already changes the
*_read_pending() functions to return the number of bytes in the buffer
rather than just a boolean. The current callers don't need that, but
the subsequent fix will.

Author: Jacob Champion <jacob.champion@enterprisedb.com>
Discussion: https://postgr.es/m/CAOYmi%2BmpymrgZ76Jre2dx_PwRniS9YZojwH0rZnTuiGHCsj0rA%40mail.gmail.com
Backpatch-through: 14

Branch
------
REL_19_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/eeb2940ae83cb6a5e48e90465bea0cede341ea59

Modified Files
--------------
src/interfaces/libpq/fe-misc.c           |  6 ++----
src/interfaces/libpq/fe-secure-gssapi.c  |  7 +++++++
src/interfaces/libpq/fe-secure-openssl.c | 34 +++++++++++++++++++++++++++++---
src/interfaces/libpq/fe-secure.c         | 22 +++++++++++++++++++++
src/interfaces/libpq/libpq-int.h         |  6 ++++--
5 files changed, 66 insertions(+), 9 deletions(-)



view thread (7+ messages)  latest in thread

Message-ID: <E1wh8AA-00019v-1Y@gemulon.postgresql.org>
Permalink:  ../E1wh8AA-00019v-1Y@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1wh8AA-00019v-1Y@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: heikki.linnakangas@iki.fi, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: libpq: Extend "read pending" check from SSL to GSS
  In-Reply-To: <E1wh8AA-00019v-1Y@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox