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 1kaPv5-00023a-0w for pgsql-committers@arkaria.postgresql.org; Wed, 04 Nov 2020 21:02:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kaPv3-0006uj-Gy for pgsql-committers@arkaria.postgresql.org; Wed, 04 Nov 2020 21:02:13 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaPv3-0006ub-BV for pgsql-committers@lists.postgresql.org; Wed, 04 Nov 2020 21:02:13 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaPv0-0006bS-Lu for pgsql-committers@lists.postgresql.org; Wed, 04 Nov 2020 21:02:12 +0000 Received: from hnk.local (p1295030-ipngn4902funabasi.chiba.ocn.ne.jp [153.166.85.30]) by oss.nttdata.com (Postfix) with ESMTPSA id D7E1F6238E; Thu, 5 Nov 2020 06:02:05 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.3 at oss.nttdata.com Subject: Re: pgsql: Get rid of the dedicated latch for signaling the startup process To: Heikki Linnakangas , Fujii Masao , pgsql-committers@lists.postgresql.org References: <5c1f8a85-747c-7bf9-241e-dd467d8a3586@iki.fi> <3d3c42ca-c1bd-605d-71cf-8cd6353e895b@iki.fi> From: Fujii Masao Message-ID: <8f02685c-4029-c038-8bbb-99fe22d09379@oss.nttdata.com> Date: Thu, 5 Nov 2020 06:02:05 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <3d3c42ca-c1bd-605d-71cf-8cd6353e895b@iki.fi> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/11/05 5:36, Heikki Linnakangas wrote: > On 04/11/2020 15:17, Heikki Linnakangas wrote: >> On 04/11/2020 14:03, Fujii Masao wrote: >>> Or ISTM that WakeupRecovery() should set the latch only when the latch >>> has not been reset to NULL yet. >> >> Got to be careful with race conditions, if the latch is set to NULL at >> the same time that WakeupRecovery() is called. > > I don't think commit 113d3591b8 got this quite right: > >> void >> WakeupRecovery(void) >> { >>     if (XLogCtl->recoveryWakeupLatch) >>         SetLatch(XLogCtl->recoveryWakeupLatch); >> } > > If XLogCtl->recoveryWakeupLatch is set to NULL between the if and the SetLatch, you'll still get a segfault. That's highly unlikely to happen in practice because the compiler will optimize that into a single load instruction, but could happen with -O0. I think you'd need to do the access only once, using a volatile pointer, to make that safe. Maybe it's simpler to just not reset it to NULL, after all. Yes, you're right. I agree it's simpler to remove the code resetting the latch to NULL. Also as the comment for that code explains, basically it's not necessary to reset it to NULL. Regards, -- Fujii Masao Advanced Computing Technology Center Research and Development Headquarters NTT DATA CORPORATION