Re: Use standard die() handler for SIGTERM in bgworkers - Mailing list pgsql-hackers

From Heikki Linnakangas
Subject Re: Use standard die() handler for SIGTERM in bgworkers
Date
Msg-id d7eb0f7d-c6e1-40d3-9373-5564ff20c27c@iki.fi
Whole thread Raw
In response to Re: Use standard die() handler for SIGTERM in bgworkers  (Kirill Reshke <reshkekirill@gmail.com>)
List pgsql-hackers
On 18/02/2026 10:45, Kirill Reshke wrote:
> On Wed, 18 Feb 2026 at 02:18, Heikki Linnakangas <hlinnaka@iki.fi> wrote:
>> +  <para>
>> +   The default signal handlers merely set interrupt flags
>> +   that are processed later by <function>CHECK_FOR_INTERRUPTS()</function>.
>> +   <function>CHECK_FOR_INTERRUPTS()</function> should be called in any
>> +   long-running loop to ensure that the background worker doesn't prevent the
>> +   system from shutting down in a timely fashion.
>> +  </para>
> 
> Unless you are holding LWLock (or, more generally, inside the CRIT
> section). Should we update wording for this case, or is it maybe
> already assumed in doc?

It's OK to call CHECK_FOR_INTERRUPTS() while holding locks or in a 
critical section. It's a no-op in that case.

I wouldn't go into the details here on how to use 
CHECK_FOR_INTERRUPTS(). It would be good to document all that somewhere, 
but it should go to some more general section on how to write server C 
functions as it's applicable to any C code. For background workers, I 
think the above is good.

Pushed, thanks for the review!

- Heikki




pgsql-hackers by date:

Previous
From: Nathan Bossart
Date:
Subject: Re: convert SpinLock* macros to static inline functions
Next
From: Tom Lane
Date:
Subject: Re: meson: Allow disabling static libraries