Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNhQ8-0003Tj-Kg for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Nov 2018 16:56:40 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gNhQ6-0003hM-Sd for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Nov 2018 16:56:38 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNhQ6-0003hE-LQ for pgsql-hackers@lists.postgresql.org; Fri, 16 Nov 2018 16:56:38 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gNhQ4-0004sn-A6 for pgsql-hackers@postgresql.org; Fri, 16 Nov 2018 16:56:38 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id wAGGuC27029642; Fri, 16 Nov 2018 11:56:12 -0500 From: Tom Lane To: Thomas Munro cc: Kyotaro HORIGUCHI , Heikki Linnakangas , Andres Freund , Pg Hackers Subject: Re: [HACKERS] PATCH: Keep one postmaster monitoring pipe per process In-reply-to: References: <20180719.193054.155432744.horiguchi.kyotaro@lab.ntt.co.jp> <20180906.185715.126482377.horiguchi.kyotaro@lab.ntt.co.jp> Comments: In-reply-to Thomas Munro message dated "Tue, 23 Oct 2018 17:26:37 +1300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <29640.1542387372.1@sss.pgh.pa.us> Date: Fri, 16 Nov 2018 11:56:12 -0500 Message-ID: <29641.1542387372@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Thomas Munro writes: > [ 0001-Add-WL_EXIT_ON_PM_DEATH-pseudo-event-v4.patch ] I took a quick look through this. I have no objection to the idea of letting the latch infrastructure do the proc_exit(1), but I'm wondering why this is in the thread that it's in. Is there any remaining connection to the original complaint about BSDen not coping well with lots of processes waiting on the same pipe? A couple minor code gripes: - rc = WaitLatch(MyLatch, - WL_LATCH_SET | WL_TIMEOUT | WL_POSTMASTER_DEATH, - (nap.tv_sec * 1000L) + (nap.tv_usec / 1000L), - WAIT_EVENT_AUTOVACUUM_MAIN); + WaitLatch(MyLatch, + WL_LATCH_SET | WL_TIMEOUT | WL_EXIT_ON_PM_DEATH, + (nap.tv_sec * 1000L) + (nap.tv_usec / 1000L), + WAIT_EVENT_AUTOVACUUM_MAIN); I'd advise making the code in places like this look like (void) WaitLatch(MyLatch, ...); Otherwise, you are likely to draw complaints about "return value is sometimes ignored" from Coverity and other static analyzers. The (void) cast makes it explicit that you're intentionally ignoring the result value in this one place. @@ -1021,6 +1051,19 @@ WaitEventSetWait(WaitEventSet *set, long timeout, pgstat_report_wait_end(); + /* + * Exit immediately if the postmaster died and the caller asked for + * automatic exit in that case. + */ + if (set->exit_on_postmaster_death) + { + for (i = 0; i < returned_events; ++i) + { + if (occurred_events[i].events == WL_POSTMASTER_DEATH) + proc_exit(1); + } + } + return returned_events; } Since exit_on_postmaster_death = true is going to be the normal case, it seems a bit unfortunate that we have to incur this looping every time we go through WaitEventSetWait. Can't we put the handling of this in some spot where it only gets executed when we've detected WL_POSTMASTER_DEATH, like right after the PostmasterIsAliveInternal calls? if (!PostmasterIsAliveInternal()) { + if (set->exit_on_postmaster_death) + proc_exit(1); occurred_events->fd = PGINVALID_SOCKET; occurred_events->events = WL_POSTMASTER_DEATH; occurred_events++; returned_events++; } regards, tom lane