Another WaitEventSet resource leakage in back branches

Started by Etsuro Fujitaabout 2 years ago5 messageshackers
Jump to latest
#1Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp

Hi,

While working on [1]/messages/by-id/CAPmGK15DF6EE7O6hTLbe5-fHvPDwEx9vm-BOCN3dsKOjZCo7bw@mail.gmail.com, 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.

Best regards,
Etsuro Fujita

[1]: /messages/by-id/CAPmGK15DF6EE7O6hTLbe5-fHvPDwEx9vm-BOCN3dsKOjZCo7bw@mail.gmail.com

Attachments:

fix-another-WaitEventSet-resource-leakage.patchapplication/octet-stream; name=fix-another-WaitEventSet-resource-leakage.patchDownload+38-32
#2Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Etsuro Fujita (#1)
Re: Another WaitEventSet resource leakage in back branches

On Fri, Mar 22, 2024 at 9:15 PM Etsuro Fujita <etsuro.fujita@gmail.com> 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.

I noticed that PG_FAINALLY was added in v13. I created a separate
patch for v12 using PG_CATCH instead. Patch attached. I am attaching
the previous patch for later versions as well.

I am planning to back-patch these next week.

Best regards,
Etsuro Fujita

Attachments:

fix-another-WaitEventSet-resource-leakage.patchapplication/octet-stream; name=fix-another-WaitEventSet-resource-leakage.patchDownload+38-32
fix-another-WaitEventSet-resource-leakage-PG12.patchapplication/octet-stream; name=fix-another-WaitEventSet-resource-leakage-PG12.patchDownload+39-30
#3Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Etsuro Fujita (#2)
Re: Another WaitEventSet resource leakage in back branches

On Fri, Apr 5, 2024 at 7:55 PM Etsuro Fujita <etsuro.fujita@gmail.com> wrote:

I am planning to back-patch these next week.

Done.

Best regards,
Etsuro Fujita

#4Andres Freund
andres@anarazel.de
In reply to: Etsuro Fujita (#1)
Re: Another WaitEventSet resource leakage in back branches

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

#5Etsuro Fujita
fujita.etsuro@lab.ntt.co.jp
In reply to: Andres Freund (#4)
Re: Another WaitEventSet resource leakage in back branches

Hi Andres,

On Fri, Apr 12, 2024 at 1:29 AM Andres Freund <andres@anarazel.de> wrote:

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.

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