pgsql: libpq: Fix sending queries in pipeline aborted state

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: libpq: Fix sending queries in pipeline aborted state
Date: 2021-07-09 20:11:22
Message-ID: E1m1wqI-0001q0-Lj@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

libpq: Fix sending queries in pipeline aborted state

When sending queries in pipeline mode, we were careless about leaving
the connection in the right state so that PQgetResult would behave
correctly; trying to read further results after sending a query after
having read a result with an error would sometimes hang. Fix by
ensuring internal libpq state is changed properly. All the state
changes were being done by the callers of pqAppendCmdQueueEntry(); it
would have become too repetitious to have this logic in each of them, so
instead put it all in that function and relieve callers of the
responsibility.

Add a test to verify this case. Without the code fix, this new test
hangs sometimes.

Also, document that PQisBusy() would return false when no queries are
pending result. This is not intuitively obvious, and NULL would be
obtained by calling PQgetResult() at that point, which is confusing.
Wording by Boris Kolpackov.

In passing, fix bogus use of "false" to mean "0", per Ranier Vilela.

Backpatch to 14.

Author: Álvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
Reported-by: Boris Kolpackov <boris(at)codesynthesis(dot)com>
Discussion: https://postgr.es/m/boris.20210624103805@codesynthesis.com

Branch
------
master

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

Modified Files
--------------
doc/src/sgml/libpq.sgml | 5 +-
src/interfaces/libpq/fe-exec.c | 57 ++++--
src/test/modules/libpq_pipeline/libpq_pipeline.c | 226 +++++++++++++++++++++++
3 files changed, 274 insertions(+), 14 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2021-07-09 20:59:27 pgsql: Un-break AIX build, take 2.
Previous Message Jeff Davis 2021-07-09 18:51:38 pgsql: Eliminate replication protocol error related to IDENTIFY_SYSTEM.