| From: | Heikki Linnakangas <hlinnaka(at)iki(dot)fi> |
|---|---|
| To: | Andres Freund <andres(at)anarazel(dot)de> |
| Cc: | "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org> |
| Subject: | Use standard die() handler for SIGTERM in bgworkers |
| Date: | 2026-02-17 21:18:00 |
| Message-ID: | 5238fe45-e486-4c62-a7f3-c7d8d416e812@iki.fi |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
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(dot)linnakangas(at)iki(dot)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
| Attachment | Content-Type | Size |
|---|---|---|
| 0001-Use-standard-die-handler-for-SIGTERM-in-bgworkers.patch | text/x-patch | 5.3 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Nathan Bossart | 2026-02-17 21:30:57 | Re: Use standard die() handler for SIGTERM in bgworkers |
| Previous Message | Greg Burd | 2026-02-17 21:15:02 | Re: Expanding HOT updates for expression and partial indexes |