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 1rmQcB-007mct-7n for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Mar 2024 03:58:16 +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 1rmQc9-009D3F-8E for pgsql-bugs@arkaria.postgresql.org; Tue, 19 Mar 2024 03:58:13 +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 1rmQc7-009D34-KY for pgsql-bugs@lists.postgresql.org; Tue, 19 Mar 2024 03:58:13 +0000 Received: from wfout4-smtp.messagingengine.com ([64.147.123.147]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rmQc3-005ISM-SE for pgsql-bugs@lists.postgresql.org; Tue, 19 Mar 2024 03:58:11 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfout.west.internal (Postfix) with ESMTP id C2C981C000ED; Mon, 18 Mar 2024 23:58:02 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Mon, 18 Mar 2024 23:58:03 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paquier.xyz; h= cc:cc:content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm2; t=1710820682; x=1710907082; bh=nhkvHL6Y53 RspLNIC6psuttU6RWhtftAQUsEQZQpnOE=; b=fcIlHA/PPlTa0nGWBD3exD7+L4 f0sneV5+xfaZExg3nOImIMjNwVOAqdXv0z59c6k0ddHGmietO90WzDN6qW5SQGUV c98p+zVRrOoT5UOo3sT6QnMj4wDKdEMIPwtLA6mQPpK9qPt39nxTe4CB55Wvyxbm tbVTGCtBLaVkg4ujYZJazBJAjk1YsB8oPhsv2O8MvWsGcFJZoRyX/ku0+MfUssAE uqSbfkalaRUSSOBisXkZ9gzb1ZEslHqPdblEoBxSlsitLmEHUUjImgz+wCgGy7Kf X+y3deiLij+QNAuV1GAfaI+AWdB2ghFgox5SC5SXcpkQlvdKPLHbQISuIEfQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm2; t=1710820682; x=1710907082; bh=nhkvHL6Y53RspLNIC6psuttU6RWh tftAQUsEQZQpnOE=; b=XMG9SohxNqFwr5mAIf9oyEzkIngw24F/6GrCn6aCaW2r S0ikswIrgTpD214EK5wnQHDLKzNgTMJBtXzkrKHmcDQs0bCitGs+atTdJ72MBSqV ejkumQY6Xdj3UR7JtXyFho2uKGqXTSLXoM+VY05XiRSip5Yi+K8VpNGtQ5IkGbof dASsYsVyxGCnFLoKQEYEDeQmFYrZqPxyGUisPFPSDTVg7j4aW3OwU72/aLhUGFyd r6aoE79YLNJlWRkjP+V4YcQYexbsBAvpDeo6xgvbTuw/wEHRep4mf6XyeqOIhkif T9pMWvWOtiywNms0/H26ncU/XRGu+6UgofUDxws+lw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrkeekgdeihecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecufghrlhcuvffnffculdejtddmnecujfgurhepfffhvf evuffkfhggtggujgesghdtreertddtvdenucfhrhhomhepofhitghhrggvlhcurfgrqhhu ihgvrhcuoehmihgthhgrvghlsehprghquhhivghrrdighiiiqeenucggtffrrghtthgvrh hnpeetleeifedufffhhfdtteelgeeggeffhfekueevteeigfduudevudetgfegiedvjeen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehmihgthh grvghlsehprghquhhivghrrdighiii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 18 Mar 2024 23:58:00 -0400 (EDT) Date: Tue, 19 Mar 2024 12:57:51 +0900 From: Michael Paquier To: feichanghong Cc: pgsql-bugs , andres , "sawada.mshk" , "horikyota.ntt" Subject: Re: ReplicationSlotRelease may set the statusFlags of other processes in PG14 Message-ID: References: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="mHRSu8Ntt/AHoW6h" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --mHRSu8Ntt/AHoW6h Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 16, 2024 at 10:29:03PM +0800, feichanghong wrote: > A process utilizing replication slots (usually walsender) calls callback > functions in the order of RemoveProcFromArray->ProcKill upon abnormal exi= t. > Within RemoveProcFromArray, MyProc is already removed from the ProcArray. > ProcKill then attempts to set ProcGlobal->statusFlags[MyProc->pgxactoff] = again > via ReplicationSlotRelease. By this time, the flag may already be assigne= d to > another process. Oops. > To replicate the issue, execute the following steps: > 1. Apply the attached v1-0000-v14-invalidate-pgxactoff-after-remove-pgpro= c.patch, > where pgxactoff is set to an invalid value in ProcArrayRemove, and some > checks are added. > 2. Use the SQL below to terminate the walsender process. > ``` > select pg_terminate_backend(pid) from pg_stat_activity where backend_type= =3D 'walsender'; > ``` > # Fix >=20 > To fix the issue, I have provided some patches in the attachment: > 1. Backpatching 2f6501f into the PG14 version will fix the problem. > 2. In PG14-head, ProcArrayRemove needs to reset pgxactoff, and some assert > checks should be done when setting ProcGlobal->statusFlags. Yeah, that's something that we had better fix in all stable branches. The asserts would offer some protection moving on, but I would take the safer move of only adding a protection like what you are suggestion on HEAD and not in stable branches, just in case we're missing something around them. -- Michael --mHRSu8Ntt/AHoW6h Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmX5DT8ACgkQnvQgOdby QH2GHw//ekSskK8zXIiMoOnmhWnlhO85QrzJ920T48E3q2JzidTKNERqsanR3Q6q JCZiZYqjrCi6eKJabhCnqcarvAvSMCf0fbvSAZHpccPl2gbIqNLcsZwL0xW8eRIV +J8ihKh3x1n3vcn18ZKoAxqiIY+IfZcVNrLH+lmYM5RIHjSbgXq2NqNBg1mcFA15 PMYgLg1rTVyYBst9rEwvCvg2CwFMXU5wcYSMOMktTGh9djAfh258Lg/ox6X9iUJK JVUWa5/AIdonBNHdxA8GoB9XwV7p7Cfep+YGCyUGwRPiMbNJ3Ppaup+6wD0r7qC9 auvY0NPXar500GokER+qsvkIMnnkPkZo0Ep6wYUNgaVcjYB/etECJ7SvqOEYDEze gQbFPdfO+pevwbaZQYz3yaXPKfKY4xvE7tve/cVUfit/y6GaTin6l6ta8V2vbT8E FWPt6fkOPo7uSC+701fIUL8DH07lH2Hs2iWgV6VkqKY7YuMumAnhRyD50bJn79Xc seoGNrBm+PEtYHkkToel8fcLeDGDP0elt/uwIV38t99SzcRGhkQ6K0BU9giWC68i ZAu05FFdHISWLM5+egHZ70m+Ou7OJ1u26fL63GeDro8ePDtRr6Rg/DEv3dyFYiuW TxIWsUagUnziT8P862b5RR1YKdlAzWsEjyWDQgRInPPNYdFEtuA= =d64x -----END PGP SIGNATURE----- --mHRSu8Ntt/AHoW6h--