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 1kaPWZ-0000oV-PF for pgsql-committers@arkaria.postgresql.org; Wed, 04 Nov 2020 20:36:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kaPW2-0006lG-VV for pgsql-committers@arkaria.postgresql.org; Wed, 04 Nov 2020 20:36:22 +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 1kaPW2-0006l8-Lw for pgsql-committers@lists.postgresql.org; Wed, 04 Nov 2020 20:36:22 +0000 Received: from meesny.iki.fi ([195.140.195.201]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kaPVx-0006Gq-Un for pgsql-committers@lists.postgresql.org; Wed, 04 Nov 2020 20:36:22 +0000 Received: from [192.168.1.113] (dsl-hkibng22-54faa4-119.dhcp.inet.fi [84.250.164.119]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: hlinnaka) by meesny.iki.fi (Postfix) with ESMTPSA id 71B3B202B0; Wed, 4 Nov 2020 22:36:14 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1604522174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5afvCgIIUW/zz7UY0MuUYejzZOr4gBDp3kT2vOc/lN8=; b=ZLIVz9/3bFuryKHjQPO+Pa4SIn5oGpjMh0/+HNWQMMa0r22U9PORBzMEYS6f7Xa5mzkjza y0Kx5L+Z2CYl7SoC3/QV5aBYLY7hRQuznl9OH9gTFtQrU2u5LKATAJGm2B4LMo5oE1MLYF lCBmrtzUe9nG3O5AhH/AYPgNsKw9spU= Subject: Re: pgsql: Get rid of the dedicated latch for signaling the startup process From: Heikki Linnakangas To: Fujii Masao , Fujii Masao , pgsql-committers@lists.postgresql.org References: <5c1f8a85-747c-7bf9-241e-dd467d8a3586@iki.fi> Message-ID: <3d3c42ca-c1bd-605d-71cf-8cd6353e895b@iki.fi> Date: Wed, 4 Nov 2020 22:36:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1604522174; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5afvCgIIUW/zz7UY0MuUYejzZOr4gBDp3kT2vOc/lN8=; b=Bev4FBKIwtLvTnyhhmEXM0g3FcuyHxVJxpywiYE0TV2R6MXRUD6CGaXHvhss5WJlmG2M3j 9hqQljEpan/AJoFWNlPskMj3ie3HWkL6finXotpsrqvSCLGghOGCwmUd/tuYp1HOVg8z5o 6OfBOHxyaTyN9iTFr18ZRv26rzBOF1E= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1604522174; a=rsa-sha256; cv=none; b=Arhiq4ieVE6poQgogoVJjMuqCSpQT4h0pvmvoDGz7yx0FMLCJxyAVzNF693zbR2X/usEns CwpLfIA0aPQrAgN9qdY/DPMlvKepF5lhFJPUqzd8aYrJrlNNdm1sNZVYy3rlf3tew2921I PzMyDPCntPDXL1GQe+ot2aAWxMGa9OM= List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk 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. - Heikki