Skip to content

Commit

Permalink
Initialize ListenSocket array earlier.
Browse files Browse the repository at this point in the history
After commit b0bea38, syslogger prints 63 warnings about failing to
close a listen socket at postmaster startup. That's because the
syslogger process forks before the ListenSockets array is initialized,
so ClosePostmasterPorts() calls "close(0)" 64 times. The first call
succeeds, because fd 0 is stdin.

This has been like this since commit 9a86f03 in version 13, which
moved the SysLogger_Start() call to before initializing ListenSockets.
We just didn't notice until commit b0bea38 added the LOG message.

Reported by Michael Paquier and Jeff Janes.

Author: Michael Paquier
Discussion: https://www.postgresql.org/message-id/ZOvvuQe0rdj2slA9%40paquier.xyz
Discussion: https://www.postgresql.org/message-id/ZO0fgDwVw2SUJiZx@paquier.xyz#482670177eb4eaf4c9f03c1eed963e5f
Backpatch-through: 13
  • Loading branch information
hlinnaka committed Aug 29, 2023
1 parent 8700851 commit 0c10240
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/backend/postmaster/postmaster.c
Expand Up @@ -1157,6 +1157,17 @@ PostmasterMain(int argc, char *argv[])
errmsg("could not remove file \"%s\": %m",
LOG_METAINFO_DATAFILE)));

/*
* Initialize input sockets.
*
* 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
*/
Expand Down Expand Up @@ -1191,15 +1202,7 @@ PostmasterMain(int argc, char *argv[])

/*
* 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;
Expand Down

0 comments on commit 0c10240

Please sign in to comment.