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 1tI0iz-00BSrS-Bb for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Dec 2024 07:20:05 +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 1tI0iw-00EYqH-8o for pgsql-hackers@arkaria.postgresql.org; Mon, 02 Dec 2024 07:20:03 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tI0iu-00EYq4-RY for pgsql-hackers@lists.postgresql.org; Mon, 02 Dec 2024 07:20:03 +0000 Received: from fhigh-a8-smtp.messagingengine.com ([103.168.172.159]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1tI0it-000bYT-1J for pgsql-hackers@lists.postgresql.org; Mon, 02 Dec 2024 07:20:00 +0000 Received: from phl-compute-05.internal (phl-compute-05.phl.internal [10.202.2.45]) by mailfhigh.phl.internal (Postfix) with ESMTP id 94C241140166; Mon, 2 Dec 2024 02:19:57 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-05.internal (MEProxy); Mon, 02 Dec 2024 02:19:57 -0500 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=fm1; t=1733123997; x=1733210397; bh=hDxnxeEBlR IfSNgeWv+dkLMoWXRfICmi8TSErEc+Y5M=; b=SA1x8+D+XzcJcpH2KooLJdS/np zQumeQNPErzOy1/kSqgXvH9H7aNtJ0+pUNwyNPrtfR3HlGWyMWAb54a5wkrElroO mE2yXgsNIkeWCzUYFWpkcAH+KteFSKfvOn9LXB8HWjay2YP8PNZCvXp3coh3Np0W T6pq7ZB2Gc9yHJon8EQ2ytM8RajziEsbVP414tagjWiE355ixnoFrVKLb6vUaPgW WDoRzorh8mPg7j4Km7GCyHqt68aOLTIFx54I2FQztu9+U8EX6e3gp9QIUwEkHKY8 jLOJXlyMxmT+gaz0NBCj+obrNh5T75Lr0/FKNrTSmpTPDAS4IWwbYUOJrlcA== 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-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1733123997; x=1733210397; bh=hDxnxeEBlRIfSNgeWv+dkLMoWXRfICmi8TS ErEc+Y5M=; b=48B36eHwIRYHjntm69Hoo7EEKdxnL4+QWC6r8Hmng1OvsNcMGZh xDrz6fX5BBCRhCsSiBbozTxbFGTAmqyOhn5d8U1VaYNgnMlIM3O5aVkxwgUICuc+ 6ot/vTR2Mfw8aT8OUWQ1YSX8xtYxGfH6gg/lZhBgPgAkmlTC1erWLV1WOuB96/2v +1kIxUFqXRwCT0C1zXH0RmvoEvwGz+WGDcXlrCxvI2v9IGHHBbg25CARLy40+Vh/ AZ3UgiaVUiQSPpXWl1m9S0bsZ2tVDo/7aJge/BZ/ocvt9fsORWGwDd7mH3FpZRn4 Ljjr8SgK/zfwzcMJCRZxqUNev7uAXTtm4vA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrheekgddutdegucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnegfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhf gggtuggjsehgtderredttddvnecuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruc eomhhitghhrggvlhesphgrqhhuihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteel ieefudffhffhtdetleeggeegfffhkeeuveetiefgudduvedutefggeeivdejnecuvehluh hsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhes phgrqhhuihgvrhdrgiihiidpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouh htpdhrtghpthhtoheprghmihhtrdhkrghpihhlrgduieesghhmrghilhdrtghomhdprhgt phhtthhopegrlhhvhhgvrhhrvgesrghlvhhhrdhnohdqihhprdhorhhgpdhrtghpthhtoh epphhgshhqlhdqhhgrtghkvghrsheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Mon, 2 Dec 2024 02:19:55 -0500 (EST) Date: Mon, 2 Dec 2024 16:19:40 +0900 From: Michael Paquier To: Amit Kapila Cc: Alvaro Herrera , Postgres hackers Subject: Re: Memory leak in WAL sender with pgoutput (v10~) Message-ID: References: <202411300828.hwe55pzx5a4x@alvherre.pgsql> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="HHgi9k/12f9355+d" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --HHgi9k/12f9355+d Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 02, 2024 at 11:47:09AM +0530, Amit Kapila wrote: > We already have PGOutputData->cachectx which could be used for it. I > think we should be able to reset such a context when we are > revalidating the publications. Even, if we want a new context for some > localized handling, we should add that in PGOutputData rather than a > local context as the proposed patch is doing at the very least for > HEAD. cachectx is used for the publications and the hash table holding all the RelationSyncEntry entries, but we lack control of individual parts within it. So you cannot reset the whole context when processing a publication invalication. Perhaps adding that to PGOutputData would be better, but that would be inconsistent with RelationSyncCache. > Can't we consider freeing the publication names individually that can > be backpatchable and have no or minimal risk of breaking anything? Sure. The first thing I did was a loop that goes through the publication list and does individual pfree() for the publication names. That works, but IMO that's weird as we rely on the internals of GetPublication() hidden two levels down in pg_publication.c. >> I am slightly concerned about the current design of GetPublication() >> in the long-term, TBH. LoadPublications() has hidden the leak behind >> two layers of routines in the WAL sender, and that's easy to miss once >> you call anything that loads a Publication depending on how the caller >> caches its data. So I would still choose for modifying the structure >> on HEAD removing the pstrdup() for the publication name. >> >=20 > BTW, the subscription structure also used the name in a similar way. > This will make the publication/subscription names handled differently. Good point about the inconsistency, so the name could also be switched to a fixed-NAMEDATALEN there if we were to do that. The subscription has much more pstrdup() fields, though.. How about having some Free() routines instead that deal with the whole cleanup of a single list entry? If that's kept close to the GetPublication() and GetSubscription() routines, a refresh when changing these structures would be hard to miss. -- Michael --HHgi9k/12f9355+d Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmdNX4wACgkQnvQgOdby QH2svBAAnrMLi2HJqQ9n6AFil6KqB/tarJrS1ACdfnuuIHegKTlUxfzKohX99MhM 3hq2AkkToDxaMxcQI+8oUJ72lVHqAJVVWgW1YdV1qbFVKbrOX52ISL0o2SZdTLy8 r6e/jp5q3+AWFpxhybxLMg9tpzIWxiZQVF6JL0zoh2+QBfWnIXMumdva5oqcJDRl Uo/KPmeoRA7sxfWWlsARAuKOoVWYftPJpj9u+59XIwuGSndwLXB0egD4xU/b7jAx iOtz5ONpc1lZeqbZriKLf2GVOYG54baUGvKmE2fwgvQMvNVTd1N96AjTxGpah8q7 N3Til3PerhH1kEB6zVq8Hd6dYfV8uEmzWh1Yj0ewnGCgjeWccDgHhLuxxaK4VUAO VoRuR3t7bNCeMNrNiojWrBIIiEdFv4HVxBmNeofqmL6CbYGaXlK99PvTc8CprZo5 snDrhbrCN+tSJVIOFsjpOVeBnAEQgEc7v6c7FWQdC/8N5+BGNmJNfNYcYfRkPmG/ aNjDjSaCpEhRv+YhklSIo0j93qvQ55y2Z3Rf1yWnav7t4QcvSnXcdDh47xapEKZY yoweIh9dKop4Gt3X7BNzlGdGPw9bZtYSsRj9OjeOkxpFjNy54T1FYSf19ZDnGI5I 2u7p2xNMp27E3095Y0i2Hnh2BvqXuckNhA2+BZbgPzSuQDGwt/I= =aeO/ -----END PGP SIGNATURE----- --HHgi9k/12f9355+d--