postgres.git / summary / log / commit / refs

commit    93909599cdba64c8759d646983c0a4ef93de1e50
Author:   Tom Lane <tgl@sss.pgh.pa.us>
Date:     Thu May 12 16:42:29 2022 +0000
First released in: 15.0

    libpq: drop pending pipelined commands in pqDropConnection().
    
    The original coding did this in pqDropServerData(), which seems
    fairly backwards.  Pending commands are more like already-queued
    output data, which is dropped in pqDropConnection().  Moving the
    operation means that we clear the command queue immediately upon
    detecting connection drop, which improves the sanity of subsequent
    behavior.  In particular this eliminates duplicated error message
    text as a consequence of code added in b15f25446, which supposed
    that a nonempty command queue must mean the prior operation is
    still active.
    
    There might be an argument for backpatching this to v14; but as with
    b15f25446, I'm unsure about interactions with 618c16707.  For now,
    given the lack of complaints about v14's behavior, leave it alone.
    
    Per report from Peter Eisentraut.
    
    Discussion: https://postgr.es/m/de57761c-b99b-3435-b0a6-474c72b1149a@enterprisedb.com


src/interfaces/libpq/fe-connect.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/interfaces/libpq/fe-connect.c b/src/interfaces/libpq/fe-connect.c index 4c12f1411f7..6e936bbff30 100644 --- a/src/interfaces/libpq/fe-connect.c +++ b/src/interfaces/libpq/fe-connect.c @@ -377,6 +377,7 @@ static int connectDBStart(PGconn *conn); static int connectDBComplete(PGconn *conn); static PGPing internal_ping(PGconn *conn); static PGconn *makeEmptyPGconn(void); +static void pqFreeCommandQueue(PGcmdQueueEntry *queue); static bool fillPGconn(PGconn *conn, PQconninfoOption *connOptions); static void freePGconn(PGconn *conn); static void closePGconn(PGconn *conn); @@ -462,6 +463,12 @@ pqDropConnection(PGconn *conn, bool flushInput) /* Always discard any unsent data */ conn->outCount = 0; + /* Likewise, discard any pending pipelined commands */ + pqFreeCommandQueue(conn->cmd_queue_head); + conn->cmd_queue_head = conn->cmd_queue_tail = NULL; + pqFreeCommandQueue(conn->cmd_queue_recycle); + conn->cmd_queue_recycle = NULL; + /* Free authentication/encryption state */ #ifdef ENABLE_GSS { @@ -569,12 +576,6 @@ pqDropServerData(PGconn *conn) } conn->notifyHead = conn->notifyTail = NULL; - pqFreeCommandQueue(conn->cmd_queue_head); - conn->cmd_queue_head = conn->cmd_queue_tail = NULL; - - pqFreeCommandQueue(conn->cmd_queue_recycle); - conn->cmd_queue_recycle = NULL; - /* Reset ParameterStatus data, as well as variables deduced from it */ pstatus = conn->pstatus; while (pstatus != NULL) [parent: b5f44225b833]