summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFujii Masao <fujii@postgresql.org>2025-08-03 10:50:22 +0900
committerFujii Masao <fujii@postgresql.org>2025-08-03 10:50:59 +0900
commit6914a330f019feab9fb90fc7d79c93e24ca3193f (patch)
treefcb5586858b38366e0b35c3892e082a132649a71
parent23dc277590a9208859408a6907eaed182a18d1e2 (diff)
Fix assertion failure in pgbench when handling multiple pipeline sync messages.
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
-rw-r--r--src/bin/pgbench/pgbench.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/bin/pgbench/pgbench.c b/src/bin/pgbench/pgbench.c
index f3af142f690..cccf0243f21 100644
--- a/src/bin/pgbench/pgbench.c
+++ b/src/bin/pgbench/pgbench.c
@@ -3480,6 +3480,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))
{
@@ -3494,10 +3496,16 @@ 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);
+
+ PQclear(res);
break;
}
PQclear(res);