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.96) (envelope-from ) id 1wQ2D4-001EgD-2h for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2026 12:09:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wQ2D2-00A2M6-1n for pgsql-hackers@arkaria.postgresql.org; Thu, 21 May 2026 12:09:05 +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.96) (envelope-from ) id 1wQ2D1-00A2Lx-0a for pgsql-hackers@lists.postgresql.org; Thu, 21 May 2026 12:09:05 +0000 Received: from fout-a7-smtp.messagingengine.com ([103.168.172.150]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1wQ2Cy-00000000jAm-4BLB for pgsql-hackers@postgresql.org; Thu, 21 May 2026 12:09:03 +0000 Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfout.phl.internal (Postfix) with ESMTP id D5508EC009C; Thu, 21 May 2026 08:08:58 -0400 (EDT) Received: from phl-frontend-04 ([10.202.2.163]) by phl-compute-02.internal (MEProxy); Thu, 21 May 2026 08:08:58 -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=fm3; t=1779365338; x=1779451738; bh=JWwJObKqIi 1zvwlrdMr+2k0hSx3tFnHKF+whDrdTuzc=; b=TpEtXAwXbXPXIrgNuYU+8OEkFi RbqqIETBHwct5OeXU/LGhAyBpHSz4t/4eYDhyv3xi8aCbhYay203QbYPikMlbirY yHBVgs09QH7EsaMLIGcEvSxbYIa4JGbqYrf65pQtaeLuywMdQxqiajZ6KNQnslzB 70fjd0dROwsooFONv0Yy3m/eEujRn8pywKqYI3vS7mMmsUwQMSvd0s0/0cIKY8vp hRfetAkFUQcxtts9SbatnWUyC02PiMQ412kXiTd7BELHr4IkS3LufiTBnycCA44E 5f+0VhGS7fZPnuvavZH2aZDt9Ek7B8JwEBz+j8zdeainP8CEg2/ijga4GwnQ== 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=fm3; t= 1779365338; x=1779451738; bh=JWwJObKqIi1zvwlrdMr+2k0hSx3tFnHKF+w hDrdTuzc=; b=qurcSvpYfLS+c3zGAOeFu8AR/dY0kx6Yz/B1y50Hz5QP72p4NPH ZR4XMY4dlpHRqMs8PHGOu/DwUTwQK9jLid7uLUDfv3i7unY8HkazcbDHEFsfqZaJ oegb2Bc6bW2sydNKGaPKL1iTUhCvD7Zqci831Gf8bfQNA/jkFU1o6f2KD+HWTwln gXtAtwoiQWTLh4gVXUuVHIi3rT9NrKoWfj/W1TJEKwdliJ0/jv3yPVmb5pT55PG0 Y3rof67QIMbsgVXpcBXuOFBHj4mSWYoRQfJ9MokGxC5EIQylTYwzL3Qu6GxYlrec N+B6pwOLndpmlAimEtdfPRURcUjgxi0zYKA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgddugeejgeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnegfrh hlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfhfgggtuggjsehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepteelieefudffhffhtdetleeggeeg fffhkeeuveetiefgudduvedutefggeeivdejnecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihiidp nhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoheplhhird gvvhgrnhdrtghhrghosehgmhgrihhlrdgtohhmpdhrtghpthhtohepphhgshhqlhdqhhgr tghkvghrshesphhoshhtghhrvghsqhhlrdhorhhgpdhrtghpthhtohepmhhitghhrggvlh drphgrqhhuihgvrhesghhmrghilhdrtghomhdprhgtphhtthhopeiguhhnvghnghiihhho uhesghhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Thu, 21 May 2026 08:08:57 -0400 (EDT) Date: Thu, 21 May 2026 21:08:54 +0900 From: Michael Paquier To: Chao Li Cc: PostgreSQL-development , Michael Paquier , Xuneng Zhou Subject: Re: Fix pg_stat_wal_receiver to show CONNECTING status Message-ID: References: <1F153E64-B791-42FA-A60A-64813B20B81E@gmail.com> <75CDE990-29D5-4D5C-BFE1-3840F19C0163@gmail.com> <1B695040-F544-447C-A6A8-C8BFF7F799D1@gmail.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="2mGyltIdfARiwMNv" Content-Disposition: inline In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --2mGyltIdfARiwMNv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, May 21, 2026 at 03:20:13PM +0800, Chao Li wrote: > I spent more time here, and found that it is still possible to leak > conninfo in the WAL receiver reuse path: >=20 > * WalRcvWaitForStartPosition() sets the state to WALRCV_WAITING. > * Then RequestXLogStreaming() copies raw conninfo into > * walrcv->conninfo and sets the state to WALRCV_RESTARTING. > * WalRcvWaitForStartPosition() then moves the state to > * WALRCV_CONNECTING, but this path does not clear walrcv->conninfo > * again. >=20 > The attached nocfbot_test.diff demonstrates the leak. File is missing, but I get it. This is a legit bug from what I can see, that also affects all the stable branches, not only HEAD. > Initially I thought we could also set ready_to_display to false when > setting the state to WALRCV_WAITING in WalRcvWaitForStartPosition(), > and set it back to true when switching back to > WALRCV_CONNECTING. However, that would make the WALRCV_WAITING and > WALRCV_RESTARTING states invisible in pg_stat_wal_receiver. Nah, we should not do that. We want to track the waiting and restarting states in the view. > I ended up with a solution that copies the primary connection info > to walrcv->conninfo only when RequestXLogStreaming() is switching to > WALRCV_STARTING. In the WALRCV_WAITING reuse path, the WAL receiver > keeps using the existing wrconn, so it does not need raw conninfo to > be copied into shared memory again. See the attached > nocfbot_walreceiverfuncs.c.diff. Ah, yeah. This solution to this problem makes sense. We should not clobber conninfo either in this case, or we'd lose the user-displayable string returned by walrcv_get_conninfo() (conninfo cannot be NULL based on the in-core callers of RequestXLogStreaming() AFAIK, but who knows for things out there). As mentioned above, this is a different issue than the visibility of the connection information while we are connecting, and it should be backpatched. Would you like to send a patch? -- Michael --2mGyltIdfARiwMNv Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmoO9dYACgkQnvQgOdby QH2a/xAAhhrsSzrIlB2c2ELXWHgAG7X4Hk/IWipmboZN5keIhd54MN4L+ZWaMlyy sy8n9k8jSqOQVJv5hOBSxDLVdOZS1syL35lYvBpKZwKypG5lmFGMhTJyc+4D8xJ5 4WBPsfI+CnjwPOyeLpSMMFHBtEriDBboe5IeR+okqpGdQoye/kZoZOOCvTn+yrvq jnecR39oXBv4ooXo5hdG4W66xE/mmQ4RfrJIj9seDO8qSiEi939sMqm50cb1vu1V YOrfoKlJt1ygLiyPfVqVqpu3c4rm+BE3DNO0zdwb7nO9yynbGMxDjihVEyyhaIxi 9RVV/ClDghN5D/ol71ZVDXksk6/i4Zn7SMZKtgnFdVpJGaZU5blSgiyodQf2/zc5 IRxN0gsgOlOya4fmwL+xH3i2xrXYXsRunc3qpnyxt4yRR5PwOtjPW26HIvFgTynF ormPiiLT8jN8F2KuENQaU/L3wBXUBcC9uiAHiPrwdJbOFpTjmncHv4dhVfutsksW GQSCWdQjt0kPW0yN2FA879QCrHWC6MQ2NFWl9D17vO7cZJAl+ggFLJZrduuNY+ND QH0y5TswSMenXDoU3ZrV+t9tGlBGW2njKk6EfYhy7zHNAlI7ZOhDUAQXRSUFrbmK ygx1RViJU12RgxGYqujkU/Hv5ZMkSwsAN1p3eOVBCit5kb8bsJM= =YiGa -----END PGP SIGNATURE----- --2mGyltIdfARiwMNv--