Re: Use FD_CLOEXEC on ListenSockets (was Re: Refactoring backend fork+exec code)

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема Re: Use FD_CLOEXEC on ListenSockets (was Re: Refactoring backend fork+exec code)
Дата
Msg-id ZO0fgDwVw2SUJiZx@paquier.xyz
обсуждение исходный текст
Ответ на Re: Use FD_CLOEXEC on ListenSockets (was Re: Refactoring backend fork+exec code)  (Heikki Linnakangas <hlinnaka@iki.fi>)
Ответы Re: Use FD_CLOEXEC on ListenSockets (was Re: Refactoring backend fork+exec code)  (Heikki Linnakangas <hlinnaka@iki.fi>)
Список pgsql-hackers
On Mon, Aug 28, 2023 at 11:52:15PM +0300, Heikki Linnakangas wrote:
> On 28/08/2023 18:55, Jeff Janes wrote:
>> Since this commit, I'm getting a lot (63 per restart) of messages:
>>
>>   LOG:  could not close client or listen socket: Bad file descriptor
>> All I have to do to get the message is turn logging_collector = on and
>> restart.
>>
>> The close failure condition existed before the commit, it just wasn't
>> logged before.  So, did the extra logging added here just uncover a
>> pre-existing bug?

In case you've not noticed:
https://www.postgresql.org/message-id/ZOvvuQe0rdj2slA9@paquier.xyz
But it does not really matter now ;)

> Yes, so it seems. Syslogger is started before the ListenSockets array is
> initialized, so its still all zeros. When syslogger is forked, the child
> process tries to close all the listen sockets, which are all zeros. So
> syslogger calls close(0) MAXLISTEN (64) times. Attached patch moves the
> array initialization earlier.

Yep, I've reached the same conclusion.  Wouldn't it be cleaner to move
the callback registration of CloseServerPorts() closer to the array
initialization, though?

> The first close(0) actually does have an effect: it closes stdin, which is
> fd 0. That is surely accidental, but I wonder if we should indeed close
> stdin in child processes? The postmaster process doesn't do anything with
> stdin either, although I guess a library might try to read a passphrase from
> stdin before starting up, for example.

We would have heard about that, wouldn't we?  I may be missing
something of course, but on HEAD, the array initialization is done
before starting any child processes, and the syslogger is the first
one forked.
--
Michael

Вложения

В списке pgsql-hackers по дате отправления:

Предыдущее
От: Thomas Munro
Дата:
Сообщение: Re: A failure in 031_recovery_conflict.pl on Debian/s390x
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: Debian 12 gcc warning