Skip to content

Commit 1d3ded5

Browse files
committed
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
1 parent cd45fef commit 1d3ded5

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,6 +3459,8 @@ doRetry(CState *st, pg_time_usec_t *now)
34593459
static int
34603460
discardUntilSync(CState *st)
34613461
{
3462+
bool received_sync = false;
3463+
34623464
/* send a sync */
34633465
if (!PQpipelineSync(st->con))
34643466
{
@@ -3473,10 +3475,16 @@ discardUntilSync(CState *st)
34733475
PGresult *res = PQgetResult(st->con);
34743476

34753477
if (PQresultStatus(res) == PGRES_PIPELINE_SYNC)
3478+
received_sync = true;
3479+
else if (received_sync)
34763480
{
3477-
PQclear(res);
3478-
res = PQgetResult(st->con);
3481+
/*
3482+
* PGRES_PIPELINE_SYNC must be followed by another
3483+
* PGRES_PIPELINE_SYNC or NULL; otherwise, assert failure.
3484+
*/
34793485
Assert(res == NULL);
3486+
3487+
PQclear(res);
34803488
break;
34813489
}
34823490
PQclear(res);

0 commit comments

Comments
 (0)