]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix assertion failure in pgbench when handling multiple pipeline sync messages.
authorFujii Masao <fujii@postgresql.org>
Sun, 3 Aug 2025 01:49:03 +0000 (10:49 +0900)
committerFujii Masao <fujii@postgresql.org>
Sun, 3 Aug 2025 01:49:54 +0000 (10:49 +0900)
Previously, when running pgbench in pipeline mode with a custom script
that triggered retriable errors (e.g., serialization errors),
an assertion failure could occur:

    Assertion failed: (res == ((void*)0)), function discardUntilSync, file pgbench.c, line 3515.

The root cause was that pgbench incorrectly assumed only a single
pipeline sync message would be received at the end. In reality,
multiple pipeline sync messages can be sent and must be handled properly.

This commit fixes the issue by updating pgbench to correctly process
multiple pipeline sync messages, preventing the assertion failure.

Back-patch to v15, where the bug was introduced.

Author: Fujii Masao <masao.fujii@gmail.com>
Reviewed-by: Tatsuo Ishii <ishii@postgresql.org>
Discussion: https://postgr.es/m/CAHGQGwFAX56Tfx+1ppo431OSWiLLuW72HaGzZ39NkLkop6bMzQ@mail.gmail.com
Backpatch-through: 15

src/bin/pgbench/pgbench.c

index 497a936c141f3025dbc115e9ea949110dfc140ee..125f3c7bbbe5b843e30258049b7d32162153dfe6 100644 (file)
@@ -3495,6 +3495,8 @@ doRetry(CState *st, pg_time_usec_t *now)
 static int
 discardUntilSync(CState *st)
 {
+       bool            received_sync = false;
+
        /* send a sync */
        if (!PQpipelineSync(st->con))
        {
@@ -3509,10 +3511,21 @@ discardUntilSync(CState *st)
                PGresult   *res = PQgetResult(st->con);
 
                if (PQresultStatus(res) == PGRES_PIPELINE_SYNC)
+                       received_sync = true;
+               else if (received_sync)
                {
-                       PQclear(res);
-                       res = PQgetResult(st->con);
+                       /*
+                        * PGRES_PIPELINE_SYNC must be followed by another
+                        * PGRES_PIPELINE_SYNC or NULL; otherwise, assert failure.
+                        */
                        Assert(res == NULL);
+
+                       /*
+                        * Reset ongoing sync count to 0 since all PGRES_PIPELINE_SYNC
+                        * results have been discarded.
+                        */
+                       st->num_syncs = 0;
+                       PQclear(res);
                        break;
                }
                PQclear(res);