Convert pcp_exit_handler and wakeup_handler_parent to flag-only.

From: Koshino Taiki <koshino(at)sraoss(dot)co(dot)jp>
To: "pgpool-hackers(at)lists(dot)postgresql(dot)org" <pgpool-hackers(at)lists(dot)postgresql(dot)org>
Cc: Emond Papegaaij <emond(dot)papegaaij(at)gmail(dot)com>
Subject: Convert pcp_exit_handler and wakeup_handler_parent to flag-only.
Date: 2026-08-26 09:21:30
Message-ID: OS9P286MB6486FF7EC3D412F5D9B2E45F94AE2@OS9P286MB6486.JPNP286.PROD.OUTLOOK.COM
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-hackers

I have reviewed the patch(027-pcp-exit-handler-flag-only) from Emond.
It has also passed all regression tests.

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.

Also, regression tests passed after applying this together with the other
similar signal handler fixes, 026-close-idle-connection-flag-only and029-pcp-worker-die-flag-only.
However, 028-lifecheck-exit-handler-flag-only is failing due to a timeout
in the 004 watchdog test case, so 028 has not been posted to this ML yet.

Thank you Emond.

Taiki Koshino<koshino(at)sraoss(dot)co(dot)jp>
SRA OSS K.K.
TEL: 03-5979-2701 FAX: 03-5979-2702
URL: https://www.sraoss.co.jp/

Attachment Content-Type Size
v1-0001-Convert-pcp_exit_handler-and-wakeup_handler_paren.patch application/octet-stream 4.5 KB

Responses

Browse pgpool-hackers by date

  From Date Subject
Next Message Koshino Taiki 2026-08-26 09:21:31 Convert pcp_worker die handler to flag-only.
Previous Message Koshino Taiki 2026-08-26 07:25:18 Re: Delimit query-cache key to prevent collisions