Re: Fix resource leaks in pg_receivewal on LZ4 close failures

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
Cc: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Fix resource leaks in pg_receivewal on LZ4 close failures
Date: 2026-11-12 00:35:46
Message-ID: 6A61C511-80E5-4689-91F9-68BD9A75BC86@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Nov 11, 2026, at 23:55, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> wrote:
>
> On Wed, Nov 11, 2026 at 7:52 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
>> Which bypasses the operations for successful close(df->fd), is that intentional?
>
> Yes. Previously, if compression finalization or the final write failed,
> the function returned -1 immediately, skipping rename, unlink, and
> sync. So the patch just preserves that behavior while releasing
> the resources.
>
> Regards,
>
> --
> Fujii Masao

It’s true that the previous code returned -1 immediately on LZ4F_isError, causing the fd leak that this patch fixes. But I think that also cause a temporary file leak. In writeTimeLineHistoryFile(), there is a call:
```
/*
* If we fail to make the file, delete it to release disk space
*/
stream->walmethod->ops->close(f, CLOSE_UNLINK);
```

This call is intended to delete a temporary file, so I don’t think an LZ4F error should prevent that deletion. Maybe fix this leak as well?

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message João Rito 2026-11-12 00:36:58 Re: Offline data checksum changes can cause incorrect checksum state on standbys
Previous Message Fujii Masao 2026-11-12 00:27:02 Re: Postgres fdw: Bug in InitPgFdwOptions initialization can cause an esoteric crash