agora inbox for pgpool-committers@postgresql.org  
help / color / mirror / Atom feed
From: Taiki Koshino <koshino@sraoss.co.jp>
To: pgpool-committers@lists.postgresql.org
Subject: pgpool: Convert pcp_exit_handler and wakeup_handler_parent to flag-only
Date: Wed, 16 Sep 2026 09:16:52 +0000
Message-ID: <E1x6ll6-0000000D8OM-0NaA@gothos.postgresql.org> (raw)

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.papegaaij@gmail.com>
Reported-by: Claude Code
Author: Taiki Koshino <koshino@sraoss.co.jp>
Discussion: https://www.postgresql.org/message-id/OS9P286MB6486FF7EC3D412F5D9B2E45F94AE2%40OS9P286MB6486.JPNP286...
Backpatch-through: v4.3

Branch
------
V4_4_STABLE

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

Modified Files
--------------
src/pcp_con/pcp_child.c | 71 +++++++++++++++++++++++++++++++++++++++----------
1 file changed, 57 insertions(+), 14 deletions(-)



view thread (6+ messages)  latest in thread

Message-ID: <E1x6ll6-0000000D8OM-0NaA@gothos.postgresql.org>
Permalink:  ../E1x6ll6-0000000D8OM-0NaA@gothos.postgresql.org/
Also on:    postgresql.org/message-id/E1x6ll6-0000000D8OM-0NaA@gothos.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgpool-committers@postgresql.org
  Cc: koshino@sraoss.co.jp, pgpool-committers@lists.postgresql.org
  Subject: Re: pgpool: Convert pcp_exit_handler and wakeup_handler_parent to flag-only
  In-Reply-To: <E1x6ll6-0000000D8OM-0NaA@gothos.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox