pgpool: Convert pcp_exit_handler and wakeup_handler_parent to flag-only

From: Taiki Koshino <koshino(at)sraoss(dot)co(dot)jp>
To: pgpool-committers(at)lists(dot)postgresql(dot)org
Subject: pgpool: Convert pcp_exit_handler and wakeup_handler_parent to flag-only
Date: 2026-09-16 09:13:33
Message-ID: E1x6lht-0000000D6mJ-0o2f@gothos.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-committers

Convert pcp_exit_handler and wakeup_handler_parent to flag-only.

The signal handlers in the PCP parent process directly accessed the
pcp_worker_children list and performed child-process cleanup. These
operations are not async-signal-safe and can modify or traverse the list
while the main loop is updating it.

In particular, pcp_exit_handler() can run while the main loop is adding
or removing worker entries. This can cause the handler to traverse a
partially modified list, crash, or send a signal to a reused PID.
wakeup_handler_parent() has the same risk when forwarding SIGUSR2 to
worker processes.

The handlers also call operations such as exit(), waitpid(), close(),
and Pgpool List functions from signal context.

Changes:
Flag-only Signal Handlers: Make pcp_exit_handler() and
wakeup_handler_parent() only set volatile sig_atomic_t flags and return.

Main-loop Processing: Process pending exit and wakeup requests from the
main loop, where the worker list can be accessed safely.

Direct Restart Cleanup: Update the PCP restart path to invoke the cleanup
function directly from normal process context.

Reported-by: Emond Papegaaij <emond(dot)papegaaij(at)gmail(dot)com>
Reported-by: Claude Code
Author: Taiki Koshino <koshino(at)sraoss(dot)co(dot)jp>
Discussion: https://www.postgresql.org/message-id/OS9P286MB6486FF7EC3D412F5D9B2E45F94AE2%40OS9P286MB6486.JPNP286.PROD.OUTLOOK.COM
Backpatch-through: v4.3

Branch
------
V4_7_STABLE

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

Modified Files
--------------
src/pcp_con/pcp_child.c | 58 +++++++++++++++++++++++++++++++++++++++++--------
1 file changed, 49 insertions(+), 9 deletions(-)

Browse pgpool-committers by date

  From Date Subject
Next Message Taiki Koshino 2026-09-16 09:14:02 pgpool: Convert pcp_exit_handler and wakeup_handler_parent to flag-only
Previous Message Taiki Koshino 2026-09-16 09:12:26 pgpool: Convert pcp_exit_handler and wakeup_handler_parent to flag-only