Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5fec3c8

Browse files
committed
Initialize ListenSocket array earlier.
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/[email protected]#482670177eb4eaf4c9f03c1eed963e5f Backpatch-through: 13
1 parent f593c55 commit 5fec3c8

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/backend/postmaster/postmaster.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,17 @@ PostmasterMain(int argc, char *argv[])
11411141
errmsg("could not remove file \"%s\": %m",
11421142
LOG_METAINFO_DATAFILE)));
11431143

1144+
/*
1145+
* Initialize input sockets.
1146+
*
1147+
* Mark them all closed, and set up an on_proc_exit function that's
1148+
* charged with closing the sockets again at postmaster shutdown.
1149+
*/
1150+
for (i = 0; i < MAXLISTEN; i++)
1151+
ListenSocket[i] = PGINVALID_SOCKET;
1152+
1153+
on_proc_exit(CloseServerPorts, 0);
1154+
11441155
/*
11451156
* If enabled, start up syslogger collection subprocess
11461157
*/
@@ -1175,15 +1186,7 @@ PostmasterMain(int argc, char *argv[])
11751186

11761187
/*
11771188
* Establish input sockets.
1178-
*
1179-
* First, mark them all closed, and set up an on_proc_exit function that's
1180-
* charged with closing the sockets again at postmaster shutdown.
11811189
*/
1182-
for (i = 0; i < MAXLISTEN; i++)
1183-
ListenSocket[i] = PGINVALID_SOCKET;
1184-
1185-
on_proc_exit(CloseServerPorts, 0);
1186-
11871190
if (ListenAddresses)
11881191
{
11891192
char *rawstring;

0 commit comments

Comments
 (0)