public inbox for [email protected]  
help / color / mirror / Atom feed
From: Michael Paquier <[email protected]>
To: Postgres hackers <[email protected]>
Cc: Heikki Linnakangas <[email protected]>
Subject: Logger process and "LOG:  could not close client or listen socket: Bad file descriptor"
Date: Mon, 28 Aug 2023 09:52:09 +0900
Message-ID: <[email protected]> (raw)

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  

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.

From 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


Attachments:

  [text/x-diff] syslogger-sockets.patch (1.2K, ../[email protected]/2-syslogger-sockets.patch)
  download | inline diff:
diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.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)));
 
+	/*
+	 * 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 = 0; i < MAXLISTEN; i++)
+		ListenSocket[i] = 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)));
 
-	/*
-	 * 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 = 0; i < MAXLISTEN; i++)
-		ListenSocket[i] = PGINVALID_SOCKET;
-
-	on_proc_exit(CloseServerPorts, 0);
-
 	if (ListenAddresses)
 	{
 		char	   *rawstring;


  [application/pgp-signature] signature.asc (833B, ../[email protected]/3-signature.asc)
  download

view thread (3+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected], [email protected]
  Subject: Re: Logger process and "LOG:  could not close client or listen socket: Bad file descriptor"
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox