From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: Re: Parallel worker hangs while handling errors.
Date: Fri, 07 Aug 2020 11:36:45 -0400
Message-ID: <2754818.1596814605@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+TgmobZxfjhDTMQPE-2MgEvBKOKLhqh_qco6EgV-mDXMP77Uw@mail.gmail.com>
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>
<CALj2ACXEVxRrmrpsZxLEMKtRQdqOWQWwm=zRjPyO6_uU1KZLnQ@mail.gmail.com>
<CA+TgmobZxfjhDTMQPE-2MgEvBKOKLhqh_qco6EgV-mDXMP77Uw@mail.gmail.com>
Robert Haas <robertmhaas@gmail.com> writes:
> On Fri, Aug 7, 2020 at 5:05 AM Bharath Rupireddy
> <bharath.rupireddyforpostgres@gmail.com> wrote:
>> We intend to unblock SIGQUIT before sigsetjmp() in places like
>> bgwriter, checkpointer, walwriter and walreceiver, but we only call
>> sigdelset(&BlockSig, SIGQUIT);, Without PG_SETMASK(&BlockSig);, seems
>> like we are not actually unblocking SIQUIT and quickdie() will never
>> get called in these processes if (sigsetjmp(local_sigjmp_buf, 1) !=
>> 0){....}
> Yeah, maybe so. This code has been around for a long time and I'm not
> sure what the thought process behind it was, but I don't see a flaw in
> your analysis here.
I think that code is the way it is intentionally: the idea is to not
accept any signals until we reach the explicit "PG_SETMASK(&UnBlockSig);"
call further down, between the sigsetjmp stanza and the main loop.
The sigdelset call, just like the adjacent pqsignal calls, is
preparatory setup; it does not intend to allow anything to happen
immediately.
In general, you don't want to accept signals in that area because the
process state may not be fully set up yet. You could argue that the
SIGQUIT handler has no state dependencies, making it safe to accept
SIGQUIT earlier during startup of one of these processes, and likewise
for them to accept SIGQUIT during error recovery. But barring actual
evidence of a problem with slow SIGQUIT response in these areas I'm more
inclined to leave well enough alone. Changing this would add hazards,
e.g. if somebody ever changes the behavior of the SIGQUIT handler, so
I'd want some concrete evidence of a benefit. It seems fairly
irrelevant to the problem at hand with bgworkers, anyway.
As for said problem, I concur with Robert that the v4 patch seems pretty
dubious; it's adding a lot of barely-thought-out mechanism for no
convincing gain in safety. I think the v1 patch was more nearly the right
thing, except that the unblock needs to happen a tad further down, as
attached (this is untested but certainly it should pass any test that v1
passed). I didn't do anything about rewriting the bogus comment just
above the sigsetjmp call, but I agree that that should happen too.
regards, tom lane
Attachments:fix-parallel-worker-hang-v5.patch (text/x-diff, 723B) downloaddiff --git a/src/backend/postmaster/bgworker.c b/src/backend/postmaster/bgworker.cindex beb5e85434..dd22241600 100644--- a/src/backend/postmaster/bgworker.c+++ b/src/backend/postmaster/bgworker.c@@ -753,7 +753,14 @@ StartBackgroundWorker(void)
/* Prevent interrupts while cleaning up */
HOLD_INTERRUPTS();
- /* Report the error to the server log */+ /*+ * sigsetjmp will have blocked all signals, but we may need to accept+ * signals while communicating with our parallel leader. Once we've+ * done HOLD_INTERRUPTS() it should be safe to unblock signals.+ */+ BackgroundWorkerUnblockSignals();++ /* Report the error to the parallel leader and the server log */
EmitErrorReport();
/*
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, bharath.rupireddyforpostgres@gmail.com
Subject: Re: Parallel worker hangs while handling errors.
In-Reply-To: <2754818.1596814605@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> <CALj2ACXEVxRrmrpsZxLEMKtRQdqOWQWwm=zRjPyO6_uU1KZLnQ@mail.gmail.com> <CA+TgmobZxfjhDTMQPE-2MgEvBKOKLhqh_qco6EgV-mDXMP77Uw@mail.gmail.com> <2754818.1596814605@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