From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: vignesh C <vignesh21@gmail.com>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>
Subject: Re: Parallel worker hangs while handling errors.
Date: Thu, 03 Sep 2020 17:29:35 -0400
Message-ID: <792142.1599168575@sss.pgh.pa.us> (raw)
In-Reply-To: <770279.1599166903@sss.pgh.pa.us>
References: <CALDaNm1d1hHPZUg3xU4XjtWBOLCrA+-2cJcLpw-cePZ=GgDVfA@mail.gmail.com>
<CALj2ACVBLox7LvCKpWd7k-kubwrmeRFjZRTrnGHN6RZQgG4cxw@mail.gmail.com>
<CALDaNm2g5GgBpzGgdwhFgxD=ur42O+Fh+prp-xiyHp+feB+q=w@mail.gmail.com>
<CALj2ACX=iLQyY9-htQvvXG1ER_6wM5DELy8k5quA+gRLHDSxDA@mail.gmail.com>
<CALDaNm04E=fbixNSqEeb4PWGdeYY26OZ-4bXNayKR2QoV6i=Yg@mail.gmail.com>
<CALj2ACX9eUkKy3UrAv+bDx3QYdS8RLBp8Rfq8FSQHOmrXtGe1Q@mail.gmail.com>
<CALDaNm1O1mauSawnz-He3x6PPy91H_GMqWc9gsBezejm6QuZ+w@mail.gmail.com>
<CALj2ACWB9P6ocrzTQDTB7wT3gdtc1m7fntnPpBbNb3ZjOGiMrQ@mail.gmail.com>
<CA+TgmoZAya0STWjtHdhr1FgeSV4EtLf69DkYFSG4ZjbHPLe7gw@mail.gmail.com>
<CALDaNm3hi_NKnJLaiXdTZ-us50kexR-eFH0rJ5p+TjV=yeD9Og@mail.gmail.com>
<770279.1599166903@sss.pgh.pa.us>
I wrote:
> As for the question of SIGQUIT handling, I see that postgres.c
> does "PG_SETMASK(&BlockSig)" immediately after applying the sigdelset
> change, so there probably isn't any harm in having the background
> processes do likewise.
Concretely, something about like this (I just did the bgwriter, but
we'd want the same in all the background processes). I tried to
respond to Robert's complaint about the inaccurate comment just above
sigsetjmp, too.
This passes check-world, for what little that's worth.
regards, tom lane
Attachments:clean-up-background-SIGQUIT-handling-wip.patch (text/x-diff, 1.5K) downloaddiff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bgwriter.cindex 069e27e427..3ae7901bf6 100644--- a/src/backend/postmaster/bgwriter.c+++ b/src/backend/postmaster/bgwriter.c@@ -117,6 +117,7 @@ BackgroundWriterMain(void)
/* We allow SIGQUIT (quickdie) at all times */
sigdelset(&BlockSig, SIGQUIT);
+ PG_SETMASK(&BlockSig);
/*
* We just started, assume there has been either a shutdown or
@@ -140,7 +141,19 @@ BackgroundWriterMain(void)
/*
* If an exception is encountered, processing resumes here.
*
- * See notes in postgres.c about the design of this coding.+ * You might wonder why this isn't coded as an infinite loop around a+ * PG_TRY construct. The reason is that this is the bottom of the+ * exception stack, and so with PG_TRY there would be no exception handler+ * in force at all during the CATCH part. By leaving the outermost setjmp+ * always active, we have at least some chance of recovering from an error+ * during error recovery. (If we get into an infinite loop thereby, it+ * will soon be stopped by overflow of elog.c's internal state stack.)+ *+ * Note that we use sigsetjmp(..., 1), so that the prevailing signal mask+ * (to wit, BlockSig) will be restored when longjmp'ing to here. Thus,+ * signals will be blocked until we complete error recovery. It might+ * seem that this policy makes the HOLD_INTERRUPTS() call redundant, but+ * it is not since InterruptPending might be set already.
*/
if (sigsetjmp(local_sigjmp_buf, 1) != 0)
{
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: tgl@sss.pgh.pa.us, robertmhaas@gmail.com, vignesh21@gmail.com, bharath.rupireddyforpostgres@gmail.com, alvherre@2ndquadrant.com
Subject: Re: Parallel worker hangs while handling errors.
In-Reply-To: <792142.1599168575@sss.pgh.pa.us>
References: <CALDaNm1d1hHPZUg3xU4XjtWBOLCrA+-2cJcLpw-cePZ=GgDVfA@mail.gmail.com> <CALj2ACVBLox7LvCKpWd7k-kubwrmeRFjZRTrnGHN6RZQgG4cxw@mail.gmail.com> <CALDaNm2g5GgBpzGgdwhFgxD=ur42O+Fh+prp-xiyHp+feB+q=w@mail.gmail.com> <CALj2ACX=iLQyY9-htQvvXG1ER_6wM5DELy8k5quA+gRLHDSxDA@mail.gmail.com> <CALDaNm04E=fbixNSqEeb4PWGdeYY26OZ-4bXNayKR2QoV6i=Yg@mail.gmail.com> <CALj2ACX9eUkKy3UrAv+bDx3QYdS8RLBp8Rfq8FSQHOmrXtGe1Q@mail.gmail.com> <CALDaNm1O1mauSawnz-He3x6PPy91H_GMqWc9gsBezejm6QuZ+w@mail.gmail.com> <CALj2ACWB9P6ocrzTQDTB7wT3gdtc1m7fntnPpBbNb3ZjOGiMrQ@mail.gmail.com> <CA+TgmoZAya0STWjtHdhr1FgeSV4EtLf69DkYFSG4ZjbHPLe7gw@mail.gmail.com> <CALDaNm3hi_NKnJLaiXdTZ-us50kexR-eFH0rJ5p+TjV=yeD9Og@mail.gmail.com> <770279.1599166903@sss.pgh.pa.us> <792142.1599168575@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox