Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDwnc-0003Pd-TA for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Sep 2020 21:29:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kDwnb-0000SS-QU for pgsql-hackers@arkaria.postgresql.org; Thu, 03 Sep 2020 21:29:39 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDwnb-0000SK-Je for pgsql-hackers@lists.postgresql.org; Thu, 03 Sep 2020 21:29:39 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kDwnZ-0003jG-HK for pgsql-hackers@lists.postgresql.org; Thu, 03 Sep 2020 21:29:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 083LTZDT792143; Thu, 3 Sep 2020 17:29:35 -0400 From: Tom Lane To: Robert Haas cc: vignesh C , Bharath Rupireddy , Alvaro Herrera , PostgreSQL Hackers Subject: Re: Parallel worker hangs while handling errors. In-reply-to: <770279.1599166903@sss.pgh.pa.us> References: <770279.1599166903@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Thu, 03 Sep 2020 17:01:43 -0400" MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----- =_aaaaaaaaaa0" Content-ID: <792095.1599168519.0@sss.pgh.pa.us> Date: Thu, 03 Sep 2020 17:29:35 -0400 Message-ID: <792142.1599168575@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk ------- =_aaaaaaaaaa0 Content-Type: text/plain; charset="us-ascii" Content-ID: <792095.1599168519.1@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 ------- =_aaaaaaaaaa0 Content-Type: text/x-diff; name="clean-up-background-SIGQUIT-handling-wip.patch"; charset="us-ascii" Content-ID: <792095.1599168519.2@sss.pgh.pa.us> Content-Description: clean-up-background-SIGQUIT-handling-wip.patch Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/postmaster/bgwriter.c b/src/backend/postmaster/bg= writer.c index 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 handl= er + * in force at all during the CATCH part. By leaving the outermost setj= mp + * always active, we have at least some chance of recovering from an err= or + * 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 mas= k + * (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) !=3D 0) { ------- =_aaaaaaaaaa0--