Fix signal handler in pgpool main

From: Tatsuo Ishii <ishii(at)postgresql(dot)org>
To: pgpool-hackers(at)lists(dot)postgresql(dot)org
Cc: emond(dot)papegaaij(at)gmail(dot)com
Subject: Fix signal handler in pgpool main
Date: 2026-06-08 01:33:12
Message-ID: 20260608.103312.126925225500634683.ishii@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgpool-hackers

I got a bug report regarding pgpool main process from Emond Papegaaij:
its exit/reload signal handler uses non signal safe functions, and it
could lead to a crash of the process.

Attached is the patch from him generated by Claude Code, with slight
modifications by me.

Basically it changes the signal handler to async-signal-safe calls
only: capture the signal number into a new volatile sig_atomic_t
main_exit_request, write one byte to the existing self-pipe to wake
the main loop, restore errno, and return. The actual shutdown is
performed synchronously by a new do_shutdown() function called from
the pgpol main loop at the top of every iteration (via
check_requests()) and also right after the inner pool_pause() returns,
so a signal arriving during the 2-second select() sleep is acted on
without an extra tick of latency.

I think this patch is important and worth to apply to all supported
branches.

However, since it touches one of the most critical part of pgpool, I
would like to apply to master branch first and see how our build-farm
acts before back patching (it will take a few days).

Comments?
--
Tatsuo Ishii
SRA OSS K.K.
English: http://www.sraoss.co.jp/index_en/
Japanese:http://www.sraoss.co.jp

Attachment Content-Type Size
v1-0001-Do-not-use-signal-unsafe-functions-in-pgpool-main.patch text/x-patch 8.1 KB

Browse pgpool-hackers by date

  From Date Subject
Next Message Emond Papegaaij 2026-06-11 07:59:38 Use-after-free crash
Previous Message Tatsuo Ishii 2026-06-07 03:14:51 Re: Race condition in pcp_node_info can cause it to hang