pgpool: Fix segfault when a watchdog sync changes the primary under run

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: pgpool-committers(at)lists(dot)postgresql(dot)org
Subject: pgpool: Fix segfault when a watchdog sync changes the primary under run
Date: 2026-11-13 01:14:48
Message-ID: E1xRfsO-0000000317P-2H2K@gothos.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-committers

Fix segfault when a watchdog sync changes the primary under running children.

sync_backend_from_watchdog() applies a failover performed by the leader
watchdog node: it updates the backend status, Req_info->primary_node_id and
Req_info->main_node_id, and only then kills and re-forks the children.
Unlike failover() it did not set Req_info->switching, so a child processing
a query meanwhile could get the new primary node from
pool_virtual_main_db_node_id(). If its session had no connection to that
node, for example because the node was down when the session started, the
child dereferenced a NULL connection slot (MAIN(backend)->fd in
read_packets_and_process()).

Set Req_info->switching while syncing, as failover() does, so children wait
for the sync to finish or to be killed. Requests registered while switching
is set do not wake up the main process, so raise the failover interrupt when
the sync ends with requests queued.

Author: Emond Papegaaij <emond(dot)papegaaij(at)gmail(dot)com>
Reported-by: Claude
Reviewed-by: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Backpatch-through: v4.3

Branch
------
V4_7_STABLE

Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=908ac2ea76ba741d16758068aa76b7b59a36ca38

Modified Files
--------------
src/main/pgpool_main.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)

Browse pgpool-committers by date

  From Date Subject
Next Message Tatsuo Ishii 2026-11-13 01:14:53 pgpool: Fix segfault when a watchdog sync changes the primary under run
Previous Message Tatsuo Ishii 2026-11-13 01:14:43 pgpool: Fix segfault when a watchdog sync changes the primary under run