Use standard die() handler for SIGTERM in bgworkers
Heikki Linnakangas <hlinnaka@iki.fi>
From: Heikki Linnakangas <hlinnaka@iki.fi>
To: Andres Freund <andres@anarazel.de>
Cc: "pgsql-hackers@postgresql.org" <pgsql-hackers@postgresql.org>
Date: 2026-02-17T21:18:00Z
Lists: pgsql-hackers
Attachments
- 0001-Use-standard-die-handler-for-SIGTERM-in-bgworkers.patch (text/x-patch) patch 0001
Starting a separate thread for this change that was part of the giant
"Interrupts vs signals" patch set
[https://www.postgresql.org/message-id/818bafaf-1e77-4c78-8037-d7120878d87c%40iki.fi]
On 14/02/2026 23:56, Andres Freund wrote:
>> From 63d1a57f4906a924c426def4e1a7f27a71611b28 Mon Sep 17 00:00:00 2001
>> From: Heikki Linnakangas <heikki.linnakangas@iki.fi>
>> Date: Tue, 20 Jan 2026 16:57:25 +0200
>> Subject: [PATCH 3/5] Use standard die() handler for SIGTERM in bgworkers
>> -/*
>> - * Standard SIGTERM handler for background workers
>> - */
>> -static void
>> -bgworker_die(SIGNAL_ARGS)
>> -{
>> - sigprocmask(SIG_SETMASK, &BlockSig, NULL);
>> -
>> - ereport(FATAL,
>> - (errcode(ERRCODE_ADMIN_SHUTDOWN),
>> - errmsg("terminating background worker \"%s\" due to administrator command",
>> - MyBgworkerEntry->bgw_type)));
>> -}
>> -
>> /*
>> * Main entry point for background worker processes.
>> */
>
> Uh, huh. So we were defaulting to completely unsafe code in bgworkers all this
> time? This obviously can self-deadlock against memory allocations etc in the
> interrupted code... Or cause confusion with the IO streams for stderr. Or ...
Yep.
Here's this patch again, now with updated documentation.
> We really need some instrumentation that fails if we do allocations in signal
> handlers etc.
Yeah, that would be nice..
- Heikki
Commits
-
Use standard die() handler for SIGTERM in bgworkers
- d62dca3b2974 19 (unreleased) landed