Subject: Re: Another WaitEventSet resource leakage in back branches

From: Andres Freund <[email-masked]>
Date: Thu, 11 Apr 2024 09:29:46 -0700

Hi,

On 2024-03-22 21:15:45 +0900, Etsuro Fujita wrote:
> While working on [1], I noticed $SUBJECT: WaitLatchOrSocket in back
> branches is ignoring the possibility of failing partway through, too.
> I added a PG_FAINALLY block to that function, like commit 555276f85.
> Patch attached.

Could you expand a bit on the concrete scenario you're worried about here?
PG_TRY/CATCH aren't free, so adding something like this to a quite common
path, in the back branches, without a concrete analysis as to why it's needed,
seems a bit scary.

Greetings,

Andres Freund

---

From: Etsuro Fujita <[email-masked]>
Date: Fri, 12 Apr 2024 20:21:24 +0900

Hi Andres,

> path, in the back branches, without a concrete analysis as to why it's needed,

What I am worried about is that system calls used in
WaitLatchOrSocket, like epoll_ctl, might fail, throwing an error
(epoll_ctl might fail due to eg, ENOMEM or ENOSPC).  The probability
of such failures would be pretty low, but not zero.

This causes more problems than it solves?

Thanks for the comment!

Best regards,
Etsuro Fujita