pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: psql: Abort connection when using \syncpipeline after COPY TO/FR
Date: Wed, 04 Jun 2025 00:02:06 +0000
Message-ID: <E1uMba2-0004WC-0s@gemulon.postgresql.org> (raw)

psql: Abort connection when using \syncpipeline after COPY TO/FROM

When the backend reads COPY data, it ignores all sync messages, as per
c01641f8aed0.  With psql pipelines, it is possible to manually send sync
messages with \sendpipeline which leaves the frontend in an
unrecoverable state as the backend will not send the necessary
ReadyForQuery message that is expected to feed psql result consumption
logic.

It could be possible to artificially reduce the piped_syncs and
requested_results, however libpq's state would still have queued sync
messages in its command queue, and the only way to consume those without
directly calling pqCommandQueueAdvance() is to process ReadyForQuery
messages that won't be sent since the backend ignores these.  Perhaps
this could be improved in the future, but I am not really excited about
introducing this amount of complications in libpq to manipulate the
message queues without a better use case to support it.

Hence, this patch aborts the connection if we detect excessive sync
messages after a COPY in a pipeline to avoid staying in an inconsistent
protocol state, which is the best thing we can do with pipelines in
psql for now.  Note that this change does not prevent wrapping a set
of queries inside a block made of \startpipeline and \endpipeline, only
the use of \syncpipeline for a COPY.

Reported-by: Nikita Kalinin <n.kalinin@postgrespro.ru>
Author: Anthonin Bonnefoy <anthonin.bonnefoy@datadoghq.com>
Discussion: https://postgr.es/m/18944-8a926c30f68387dd@postgresql.org

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/7f3381c7ee661e552634f06509a3452988a15845

Modified Files
--------------
src/bin/psql/common.c       | 15 +++++++++++++++
src/bin/psql/t/001_basic.pl | 22 ++++++++++++++++++++--
2 files changed, 35 insertions(+), 2 deletions(-)



Message-ID: <E1uMba2-0004WC-0s@gemulon.postgresql.org>
Permalink:  ../E1uMba2-0004WC-0s@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1uMba2-0004WC-0s@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: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: psql: Abort connection when using \syncpipeline after COPY TO/FR
  In-Reply-To: <E1uMba2-0004WC-0s@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