pgsql: Fix handling of errors in libpq pipelines

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Fix handling of errors in libpq pipelines
Date: 2023-12-05 11:43:58
Message-ID: E1rATqH-008hbg-LY@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix handling of errors in libpq pipelines

The logic to keep the libpq command queue in sync with queries that have
been processed had a bug when errors were returned for reasons other
than problems in queries -- for example, when a connection is lost. We
incorrectly consumed an element from the command queue every time, but
this is wrong and can lead to the queue becoming empty ahead of time,
leading to later malfunction: PQgetResult would return nothing,
potentially causing the calling application to enter a busy loop.

Fix by making the SYNC queue element a barrier that can only be consumed
when a SYNC message is received.

Backpatch to 14.

Reported by: Иван Трофимов (Ivan Trofimov) <i(dot)trofimow(at)yandex(dot)ru>
Discussion: https://postgr.es/m/17948-fcace7557e449957@postgresql.org

Branch
------
REL_16_STABLE

Details
-------
https://git.postgresql.org/pg/commitdiff/878aa41f8257b1e8b36a690d62475b4e6f1ede33

Modified Files
--------------
src/interfaces/libpq/fe-exec.c | 53 +++++++++++++++++++++++++------------
src/interfaces/libpq/fe-protocol3.c | 9 ++-----
src/interfaces/libpq/libpq-int.h | 3 ++-
3 files changed, 40 insertions(+), 25 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2023-12-05 13:35:56 pgsql: Fix incorrect error message for IDENTIFY_SYSTEM
Previous Message Amit Kapila 2023-12-05 03:51:50 pgsql: Fix a random failure in 003_logical_slots.pl.