Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhPeJ-00BKij-Pv for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2024 07:55:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rhPeG-00Ehb1-Sz for pgsql-hackers@arkaria.postgresql.org; Tue, 05 Mar 2024 07:55:41 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhPeG-00Ehat-Fn for pgsql-hackers@lists.postgresql.org; Tue, 05 Mar 2024 07:55:41 +0000 Received: from lahtoruutu.iki.fi ([2a0b:5c81:1c1::37]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rhPeB-002rKs-Fa for pgsql-hackers@lists.postgresql.org; Tue, 05 Mar 2024 07:55:39 +0000 Received: from [192.168.1.115] (dsl-hkibng22-54f8db-125.dhcp.inet.fi [84.248.219.125]) (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 lahtoruutu.iki.fi (Postfix) with ESMTPSA id 4TpntF098zz49Q4M; Tue, 5 Mar 2024 09:55:32 +0200 (EET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1709625334; 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=4SX/lVT3YAJgiixw9D05hAWvY1qpx6/46TRj3FNXcnk=; b=La9l9l0udiZrfkr95m+tjFcL4Jy/rnRyphcbHtVTsGtwWo7nkdbTBLQxkMzyFdSwAPVviF 14pQjkWCg7ZJWv+spNi7k8AeY8pDkgLAh2QCaVsNX1HQh2s5E1Y+S1QXdmYNVM3eXNkfyL BbpZIImB06ybDL0/rYXKDLgF/V13n1rnTGJ2DMxDoJO5af8VF6O4hKnjwGS+Kc+7MweQG6 LUdcW/xtv/I33J/0oXZSOJx5tO+6ODJzzFucokpz3wuvehHSBtWE06yOelEBdHnXS1FWmC X1F8DABztKPizFG376KiVE6jTt4XyOXGQn+GA71zhAVnmffWWlUp78OQUjjf6g== ARC-Seal: i=1; s=lahtoruutu; d=iki.fi; t=1709625334; a=rsa-sha256; cv=none; b=VBnBIodQMJFS7fDRAUFMKSbuwTQ13D4LlRf8+xjxa4CAfpB5g3ZsIXoceaUmAL4FpX384X mCyjk1hcm6MZBQIQ/9xqfwoqBlVk049ybyIlljxLg3zQ+PXRATU+LBD47OZ0XM2noQvg6i yICOiCX23lAZ0fg9aWhqvLuHgWoQd0g03UwKwBFI/JaqBT8q83HknYbhYUG+uCM6D/9MPX wVNszAfG7yMq+9Atw4uPC6X5KHZSpL1V7N9CWADyo/ElwpThHUFKHsCZonwbn1rLVjLXnd k0MzOa5WGG6DE1Zv6xEMYGG9sC1JSq1nEcjQQXo0FhWEL5eIu7IMoRvL4UIKnw== ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=hlinnaka smtp.mailfrom=hlinnaka@iki.fi ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=lahtoruutu; t=1709625334; 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=4SX/lVT3YAJgiixw9D05hAWvY1qpx6/46TRj3FNXcnk=; b=lf+NZu7gkz+G7+v3FzY0/fXw1lPV8uZ8ws8owFxnH3X/P1agdfsq7MH+UrOjFWMFBwjYYE 6quh2HXxNNAj8/WXEXgwhFP+s4lqeLUMO4EDUoF1Rcc3F8Z8Jiw80XheN0bMJ8PPQNQOiG 5RIIx1uUYr524uFoLMBzpnhCeIFCdktQS/OsVkzrTUvqSNAmwnuX554LTM69R95762Y769 tX/1/nHhTKPY7EvCK1oyUEwCrzMXDC/aKNX9O80IHAYoD09M4/EPoAAxpIq7t6KcQif4uX Ynrgch5ATeoe9bclyv8MbbvNtRH5tPHTF6gDBEtqYDPRQiKn2mrIX37Nmj2mqA== Message-ID: <5e803e21-789d-4399-970f-b6ea56e6df9b@iki.fi> Date: Tue, 5 Mar 2024 09:55:32 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: Missing LWLock protection in pgstat_reset_replslot() Content-Language: en-US To: Bertrand Drouvot , pgsql-hackers@lists.postgresql.org References: From: Heikki Linnakangas In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 01/03/2024 12:15, Bertrand Drouvot wrote: > Hi hackers, > > I think that pgstat_reset_replslot() is missing LWLock protection. Indeed, we > don't have any guarantee that the slot is active (then preventing it to be > dropped/recreated) when this function is executed. Yes, so it seems at quick glance. We have a similar issue in pgstat_fetch_replslot(); it might return stats for wrong slot, if the slot is dropped/recreated concurrently. Do we care? > --- a/src/backend/utils/activity/pgstat_replslot.c > +++ b/src/backend/utils/activity/pgstat_replslot.c > @@ -46,6 +46,8 @@ pgstat_reset_replslot(const char *name) > > Assert(name != NULL); > > + LWLockAcquire(ReplicationSlotControlLock, LW_SHARED); > + > /* Check if the slot exits with the given name. */ > slot = SearchNamedReplicationSlot(name, true); SearchNamedReplicationSlot() will also acquire the lock in LW_SHARED mode, when you pass need_lock=true. So that at least should be changed to false. -- Heikki Linnakangas Neon (https://neon.tech)