| From: | Xuneng Zhou <xunengzhou(at)gmail(dot)com> |
|---|---|
| To: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
| Cc: | PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Fujii Masao <masao(dot)fujii(at)gmail(dot)com> |
| Subject: | Re: Ensure temporary files are unlinked on errors in pg_receivewal |
| Date: | 2026-11-23 09:13:28 |
| Message-ID: | CABPTF7WM_fCD1qN1Yx2sv29uUa764A0wV9mUdmskKwVUPx7SVQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Evan,
Thanks for the raising this.
On Mon, Nov 23, 2026 at 2:56 PM Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> wrote:
> Hi,
>
> This derives from a previous patch [1] that fixed a resource leak issue in
> dir_close() for pg_receivewal. While reviewing the patch, I found a path
> where, if an LZ4 compression operation fails, the current code goes
> directly to error handling, bypassing the CLOSE_UNLINK branch, which may
> cause a temporary file leak. I raised the issue as a review comment, then
> Fujii-san considered it a separate issue that would be better fixed by a
> new patch.
>
It seems worth a small patch.
> This patch moves the CLOSE_UNLINK handling into the common cleanup path,
> so a preceding operation failure (such as LZ4 compressing or file closing)
> won't prevent unlinking the temporary file. If unlinking also fails, we
> preserve the earlier error rather than reporting the unlink failure.
>
Looks sensible to me.
> See the attached patch for the detailed changes.
>
> [1]
> https://postgr.es/m/CAHGQGwHfCrEogr6=wr0nCkQevAJ9A3HBqQRjT9iJryO7EjF6Lw@mail.gmail.com
>
>
Just a stylish comment:
+ int unlink_result = unlink(df->fullpath);
We could save the variable assignment here if you want. Otherwise, LGTM.
--
Regards,
Xuneng Zhou
HighGo Software Co., Ltd.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Bertrand Drouvot | 2026-11-23 09:22:39 | Fix relation statistics around transactional TRUNCATE |
| Previous Message | Tender Wang | 2026-11-23 09:11:23 | Re: Fix stale source values in MERGE RETURNING after a cross-partition update |