Re: BUG #19494: Error on transaction commit inside pipeline triggers psql's Assert

Alexander Law <exclusion@gmail.com>

From: Alexander Lakhin <exclusion@gmail.com>
To: Michael Paquier <michael@paquier.xyz>
Cc: pgsql-bugs@lists.postgresql.org
Date: 2026-05-31T09:00:01Z
Lists: pgsql-bugs
Hello Michael,

29.05.2026 08:00, Michael Paquier wrote:
> When ending the pipeline the loop consuming the results is stuck, so
> we could check the connection state.  We are going to enter in a
> freeze of the branches due to beta1 next week, so let's take our time.
>
> Please feel to use the v2 attached for your tests.  I am also testing
> it more on my side.

Thank you for the fix! I haven't discovered new issues so far.

I've found a way to trigger another assertion, but I don't think it's
legitimate:
--- a/src/backend/libpq/pqcomm.c
+++ b/src/backend/libpq/pqcomm.c
@@ -880,7 +880,7 @@ RemoveSocketFiles(void)
  static void
  socket_set_nonblocking(bool nonblocking)
  {
-       if (MyProcPort == NULL)
+       if ((MyProcPort == NULL) || (rand() % 10 == 0))
                 ereport(ERROR,
(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
                                  errmsg("there is no client connection")));

makes this script:
(
echo "\startpipeline"
for i in {1..50}; do echo "\syncpipeline"; done
echo "
SELECT 1;
\endpipeline

\startpipeline
SELECT 2;
\endpipeline
"
) | psql

trigger
psql: common.c:2055: ExecQueryAndProcessResults: Assertion `pset.piped_syncs > 0' failed.

Probably there could be another way to throw an ERROR on \syncpipeline,
but I have no good idea yet.

Running psql_pipeline in a loop with the above modification applied:
for i in {1..1000}; do echo "ITERATION $i"; NO_TEMP_INSTALL=1 TESTS=psql_pipeline make -s check-tests; done
I also observed the test hanging (at iterations 284. 543, 218) due to loss
of synchronization between psql and postgres.

Best regards,
Alexander

Commits

  1. psql: Fix issues with deferred errors in pipelines