Clarify or fix SIGINT handling in data checksums launcher

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Clarify or fix SIGINT handling in data checksums launcher
Date: 2026-07-11 17:44:05
Message-ID: CAHGQGwEQ1-+iPQnUpTXYiHmzSz9ufFVkOK4kL_uyTdYt7jgg0Q@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

In datachecksum_state.c, launcher_cancel_handler() currently says:

* Internal routine for reacting to SIGINT and flagging the worker to abort.
* The worker won't be interrupted immediately but will check for abort flag
* between each block in a relation.
*/

This reads to me as if canceling the launcher is expected to cause
the currently running worker to abort. However, the flag set by
launcher_cancel_handler() is process-local to the launcher.
Since the worker has its own process-local flag, it will never
observe the launcher's flag.

As a result, if the launcher receives SIGINT, the worker is not canceled.
Moreover, the launcher waits for the worker to exit before it can
terminate itself. If the worker runs for a long time, for example,
while processing a large database or waiting for a long-running session
holding temporary tables, the launcher's cancellation can be delayed
for a long time as well.

Is this intentional?

If so, I think the comment above launcher_cancel_handler() should be
updated so that it does not imply that canceling the launcher directly
causes the worker to abort.

If not, I'd like to propose the attached 0001 patch. It updates the launcher
to cancel the current worker by calling TerminateBackgroundWorker()
when it receives SIGINT. It also adds a data-checksums-specific helper
for waiting for worker startup or shutdown, to handle the cases where
SIGINT arrives while the launcher is waiting for a worker to start or exit.

While working on this, I also found that two local function prototypes
are missing and that the prototype order does not match the function
definition order. This is basically harmless, but I'm tempted to propose
the attached 0002 patch which cleans that up for consistency and readability.

Thoughts?

--
Fujii Masao

Attachment Content-Type Size
v1-0001-Make-data-checksums-launcher-cancel-its-worker.patch application/octet-stream 6.4 KB
v1-0002-Reorder-data-checksum-state-prototypes.patch application/octet-stream 2.2 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Nurlan Tulemisov 2026-07-11 18:26:12 Re: postgres_fdw: Emit message when batch_size is reduced
Previous Message Greg Burd 2026-07-11 17:37:19 Re: Tepid: selective index updates for heap relations