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 1jPptP-0002Fz-87 for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Apr 2020 16:00:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jPptN-0005c0-Ox for pgsql-hackers@arkaria.postgresql.org; Sat, 18 Apr 2020 16:00:29 +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 1jPptN-0005bt-IK for pgsql-hackers@lists.postgresql.org; Sat, 18 Apr 2020 16:00:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jPptH-0004ig-9M for pgsql-hackers@lists.postgresql.org; Sat, 18 Apr 2020 16:00:28 +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 03IG0JxW022665; Sat, 18 Apr 2020 12:00:19 -0400 From: Tom Lane To: Masahiko Sawada cc: Kyotaro Horiguchi , Fujii Masao , PostgreSQL Hackers Subject: Re: Race condition in SyncRepGetSyncStandbysPriority In-reply-to: References: <23215.1587051546@sss.pgh.pa.us> <20200417.145834.1847060913969327935.horikyota.ntt@gmail.com> <3f58063d-2544-aea8-07aa-7e0c35484187@oss.nttdata.com> <20200417.170706.1152908438290368702.horikyota.ntt@gmail.com> <3020.1587137510@sss.pgh.pa.us> Comments: In-reply-to Masahiko Sawada message dated "Sat, 18 Apr 2020 12:38:54 +0900" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <22663.1587225619.1@sss.pgh.pa.us> Date: Sat, 18 Apr 2020 12:00:19 -0400 Message-ID: <22664.1587225619@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Masahiko Sawada writes: > On Sat, 18 Apr 2020 at 00:31, Tom Lane wrote: >> + /* Quick out if not even configured to be synchronous */ >> + if (SyncRepConfig == NULL) >> + return false; > I felt strange a bit that we do the above check in > SyncRepGetSyncRecPtr() because SyncRepReleaseWaiters() which is the > only caller says the following before calling it: Notice there was such a test in SyncRepGetSyncRecPtr already --- I just moved it to be before doing some work instead of after. > Can we either change it to an assertion, move it to before acquiring > SyncRepLock in SyncRepReleaseWaiters or just remove it? I have no objection to that in principle, but it seems like it's a change in SyncRepGetSyncRecPtr's API that is not necessary to fix this bug. So I'd rather leave it to happen along with the larger API changes (getting rid of am_sync) that are proposed for v14. regards, tom lane