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 1qaQUS-009C3Z-8J for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Aug 2023 00:52:25 +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 1qaQUQ-005L6Z-UY for pgsql-hackers@arkaria.postgresql.org; Mon, 28 Aug 2023 00:52:22 +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 1qaQUP-005L6Q-DM for pgsql-hackers@lists.postgresql.org; Mon, 28 Aug 2023 00:52:22 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qaQUL-001Qfj-5P for pgsql-hackers@lists.postgresql.org; Mon, 28 Aug 2023 00:52:20 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id D10F25C0096; Sun, 27 Aug 2023 20:52:15 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Sun, 27 Aug 2023 20:52:15 -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 :message-id:mime-version:reply-to:sender:subject:subject:to:to; s=fm1; t=1693183935; x=1693270335; bh=IwYk7ic7JcvEzdrn1Ml5P5GmZ M3YWD2IkhUWp3AuwuA=; b=tlzoasneuPCqkJQNKI80BJHOaa6teqSsnaiftscoK x7jcTV+y/nvK9h9U/OpoJpXEqcp+ZJea2EUphRET4hPIOQG/LHMUGYpZ855tSGaO GNqMv/bapf13NYEBdpzB8k3p/kpMcXQJR073QckhaaVkQ66PXMMWNL5Wd01bBdZ4 kJY4/iKPb8c7L9w6KFJS/ziQWXB2Mxs6hnzIZY/1V+2rJhssz51BIlK/KQwTPOK3 v5DK/YxAaLZd4TnJDmhscw6Ig6un7IXH9qwV/ZBhbnfhroe8QuYwePL/7G5npwoZ jVDN+NN7kn/XlPkXU0GnloXRzjskry6p9UIItfkWmV0gg== 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:message-id :mime-version:reply-to:sender:subject:subject:to:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t= 1693183935; x=1693270335; bh=IwYk7ic7JcvEzdrn1Ml5P5GmZM3YWD2IkhU Wp3AuwuA=; b=2XMxh63VQSfZuvUbr7b4cHkFWmg0xWAI1qZy9XBXLGDhup4pJIc xJl7CXvN2QT1Fuh6Z+R67kSgIcgscD9gYUm8geFcDaNxTUnKOsdOt/aIK2vM3/bk 29gtmWyYPTph0xgxAIP9rYdTYHqWd1YG1zRwVHbOKT13g3R8ab2dW4KxplPhFRLB woOZ+vzfSsLtY65x3zpY02NvL6J2nhwWJ37TbPzhPWdtp7cQOQaK/G4iK0uVFEbq TK71KtW+Uboru7AQAVCv6me40Und4awPIIv2zsPoNhPWWevUDn1K7REvcFv9PAXL UM+0Hi4xY8LA4boEpl0aLOA64q2Tx7aNrTg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedviedrudeffedgfeelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne gfrhhlucfvnfffucdljedtmdenucfjughrpeffhffvvefukfggtggusehgtderredttddv necuhfhrohhmpefoihgthhgrvghlucfrrghquhhivghruceomhhitghhrggvlhesphgrqh huihgvrhdrgiihiieqnecuggftrfgrthhtvghrnhepgeffkedufeeutdffteevgeduvdff veduuefgudffgfelhfeludeghfejfeffteeinecuvehluhhsthgvrhfuihiivgeptdenuc frrghrrghmpehmrghilhhfrhhomhepmhhitghhrggvlhesphgrqhhuihgvrhdrgiihii X-ME-Proxy: Feedback-ID: i0fe9450f:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 27 Aug 2023 20:52:14 -0400 (EDT) Date: Mon, 28 Aug 2023 09:52:09 +0900 From: Michael Paquier To: Postgres hackers Cc: Heikki Linnakangas Subject: Logger process and "LOG: could not close client or listen socket: Bad file descriptor" Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="8LSby7w7SkWMQFbG" Content-Disposition: inline List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --8LSby7w7SkWMQFbG Content-Type: multipart/mixed; boundary="e2d+Op/TWPMOp+ma" Content-Disposition: inline --e2d+Op/TWPMOp+ma Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi all, (Heikki in CC.) After b0bea38705b2, I have noticed that the syslogger is generating a lot of dummy LOG entries: 2023-08-28 09:40:52.565 JST [24554] LOG: could not close client or listen socket: Bad file descriptor =20 The only reason why I have noticed this issue is because I enable the logging collector in my development scripts. Note that the pg_ctl test 004_logrotate.pl, the only one with logging_collector set, is equally able to reproduce the issue. The root of the problem is ClosePostmasterPorts() in syslogger.c, where we close the postmaster ports, but all of them are still set at 0, leading to these spurious logs. =46rom what I can see, this is is a rather old issue, because ListenSocket[] is filled with PGINVALID_SOCKET *after* starting the syslogger. It seems to me that we should just initialize the array before starting the syslogger, so as we don't get these incorrect logs? Thoughts? Please see the attached. -- Michael --e2d+Op/TWPMOp+ma Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="syslogger-sockets.patch" Content-Transfer-Encoding: quoted-printable diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/p= ostmaster.c index 41bccb46a8..acd46718fc 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -1141,6 +1141,17 @@ PostmasterMain(int argc, char *argv[]) errmsg("could not remove file \"%s\": %m", LOG_METAINFO_DATAFILE))); =20 + /* + * Establish input sockets. + * + * First, mark them all closed, and set up an on_proc_exit function that's + * charged with closing the sockets again at postmaster shutdown. + */ + for (i =3D 0; i < MAXLISTEN; i++) + ListenSocket[i] =3D PGINVALID_SOCKET; + + on_proc_exit(CloseServerPorts, 0); + /* * If enabled, start up syslogger collection subprocess */ @@ -1173,17 +1184,6 @@ PostmasterMain(int argc, char *argv[]) ereport(LOG, (errmsg("starting %s", PG_VERSION_STR))); =20 - /* - * Establish input sockets. - * - * First, mark them all closed, and set up an on_proc_exit function that's - * charged with closing the sockets again at postmaster shutdown. - */ - for (i =3D 0; i < MAXLISTEN; i++) - ListenSocket[i] =3D PGINVALID_SOCKET; - - on_proc_exit(CloseServerPorts, 0); - if (ListenAddresses) { char *rawstring; --e2d+Op/TWPMOp+ma-- --8LSby7w7SkWMQFbG Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEEG72nH6vTowiyblFKnvQgOdbyQH0FAmTr77kACgkQnvQgOdby QH2A+g/+Lzga07TiKTBlgxtKODjtg8YFUNlQms6kdkZSa5h6tfcYWvUTpU3YG1wt igSBVp3k8WBJ4k2kTo1riNH4eblki1g14BoJ4iueZ4dFVXEsz/1WsTcs7OxVeEUu bBVVvCbE5ozTtKg51wxM17RSG6HVg/BPCfUO7mG59fJm2JsHX1UHqkTF6JYcWyHn xj+BsJIjtwOLwgR79rg8Yin0SIp9cnf5wwrpz+bmyu7yreaP5WjUh3gXAhAJgt2+ 9FAG0xRfrdUpcnvY4Qjt3050U/A4idmImNCXRHtINEC6dR1FS4pFnVCGgTs2vbsv iUTm2T71RqSBhMg0UKWVo/gOssO65LQYMPHuk66NM+lEWFo5VhlAqgZNHhJ4HZ1W UE2zv9fJP15EE7m9ajJp1JlzqCKDtdp92iMPx4trqIM/I3KwCOP96SoSQrbDT78A S9/M+3MosEwa9Zf9W/7bDQvh/lsTshigCq3jqoHgMIdguV07isn/cdYZcOiWeQ3X 80NzAOBIM5WK+RMw0xKJosrdyqKbbvSo4cMITHWcyFY2gtLc47Ngs+CSMZbUVetQ BJMovn7lkm92RAS9v9HoXzYdsxZLmGklcGvOhK9GFOyLKmz2Or0iIyA+aCEu5lrt kOl9rrqHrqfFbmYRLunHNGtd5lixC3z3/hEuQxaaHK2XGd0USMs= =4w7y -----END PGP SIGNATURE----- --8LSby7w7SkWMQFbG--