Skip to content

Commit fee46ab

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 a3e8dc1 commit fee46ab

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/bin/pgbench/pgbench.c

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3495,6 +3495,8 @@ doRetry(CState *st, pg_time_usec_t *now)
34953495
static int
34963496
discardUntilSync(CState *st)
34973497
{
3498+
bool received_sync = false;
3499+
34983500
/* send a sync */
34993501
if (!PQpipelineSync(st->con))
35003502
{
@@ -3509,10 +3511,21 @@ discardUntilSync(CState *st)
35093511
PGresult *res = PQgetResult(st->con);
35103512

35113513
if (PQresultStatus(res) == PGRES_PIPELINE_SYNC)
3514+
received_sync = true;
3515+
else if (received_sync)
35123516
{
3513-
PQclear(res);
3514-
res = PQgetResult(st->con);
3517+
/*
3518+
* PGRES_PIPELINE_SYNC must be followed by another
3519+
* PGRES_PIPELINE_SYNC or NULL; otherwise, assert failure.
3520+
*/
35153521
Assert(res == NULL);
3522+
3523+
/*
3524+
* Reset ongoing sync count to 0 since all PGRES_PIPELINE_SYNC
3525+
* results have been discarded.
3526+
*/
3527+
st->num_syncs = 0;
3528+
PQclear(res);
35163529
break;
35173530
}
35183531
PQclear(res);

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy