| From: | Tatsuo Ishii <ishii(at)postgresql(dot)org> |
|---|---|
| To: | pgpool-committers(at)lists(dot)postgresql(dot)org |
| Subject: | pgpool: Fix pcp main process to remember child pids upon restarting. |
| Date: | 2026-04-27 06:44:36 |
| Message-ID: | E1wHFhs-000pKZ-2T@gothos.postgresql.org |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgpool-committers |
Fix pcp main process to remember child pids upon restarting.
Upon failove/failback, pgpool main process sends a signal to pcp main
process to request restarting, and pcp main restarts. Problem is, when
pcp main restarts, it forgets the list of pids of its child pcp worker
process. As a result, when pgpool main sends SIGUSR2 to pcp main to
wake up pcp worker process, it cannot find the pid to send the signal
to, which causes the infinite loop in pcp worker process.
Below is a reproducer script. pcp_promote_node hangs.
------------------------------------------------
pgpool_setup -n 3 --no-stop
pg_ctl -D data2 stop
while true
do
psql -p 11000 -c "show pool_nodes" test
if [ $? = 0 ];then
break;
fi
sleep 1
done
psql -p 11000 -c "show pool_nodes" test
pcp_recovery_node -p 11001 -n 2;pcp_promote_node -p 11001 -n 2 -s -g
------------------------------------------------
To fix the problem, we could delay the restarting of pcp main until it
delivers the signal. Unfortunately this does not work, since pgpool
main waits for pcp main process to exit. Thus processing failover does
not proceed in pgpool main.
So I decided to add a new shared memory area
(Req_info->pcp_worker_pids) to remember the pcp workers pids across
pcp main restarting. The array size is MAX_REQUEST_QUEUE_SIZE + some
room (currently 10). If all the slots in the area is used, a warning
will emitted. However, this should not happen in normal
circumstances.
When a child process is forked from pcp main, its pid is added to the
shared memory array. When child process exits, its pid in the array is
cleared to 0, representing an empty slot.
Author: Tatsuo Ishii <ishii(at)postgresql(dot)org>
Reported-by: Taiki Koshino <koshino(at)sraoss(dot)co(dot)jp>
Discussion: https://www.postgresql.org/message-id/20260425.223051.1207744844622514060.ishii%40postgresql.org
Backpatch-through: v4.3
Branch
------
V4_3_STABLE
Details
-------
https://git.postgresql.org/gitweb?p=pgpool2.git;a=commitdiff;h=b34d56db0e757dab0655e79d18547c94f031bd5f
Modified Files
--------------
src/include/pool.h | 14 ++++++++++++++
src/main/pgpool_main.c | 2 ++
src/pcp_con/pcp_child.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 59 insertions(+), 1 deletion(-)
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tatsuo Ishii | 2026-04-27 06:44:42 | pgpool: Fix pcp main process to remember child pids upon restarting. |
| Previous Message | Tatsuo Ishii | 2026-04-18 10:05:28 | pgpool: Feature: reload SSL certificates on SIGHUP without restart. |