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:53
Message-ID: E1xRfsT-000000031AO-1Ttj@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
------
master

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

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

Browse pgpool-committers by date

  From Date Subject
Next Message Taiki Koshino 2026-11-13 02:25:26 pgpool: Feature: Wait for follow_primary completion and report failure
Previous Message Tatsuo Ishii 2026-11-13 01:14:48 pgpool: Fix segfault when a watchdog sync changes the primary under run