Re: WAL segment file descriptor leak on read errors can PANIC the server

From: Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>
To: Michael Paquier <michael(at)paquier(dot)xyz>
Cc: Sami Imseih <samimseih(dot)pg(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: WAL segment file descriptor leak on read errors can PANIC the server
Date: 2026-10-01 04:42:00
Message-ID: CALj2ACVFgGRcEmMJ9rJqrBPx+YMgatSz=aPCfKhQh6+sMUZ5Bg@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

On Fri, Sep 25, 2026 at 4:25 PM Bharath Rupireddy
<bharath(dot)rupireddyforpostgres(at)gmail(dot)com> wrote:
>
> > segment. I would imagine here that the sane move is to register a
> > callback *iff* we open a segment. So, add a boolean flag in the state
> > tracking if the reset callback is registered, and use
> > GetMemoryChunkContext(state) to save the callback in the memory
> > context of the xlogreader state, not the CurrentMemoryContext where
> > the segment is opened.
>
> Agreed. A reader whose page_read callback reads everything from WAL
> buffers, for example with WALReadFromBuffers(), may not call
> segment_open at all, so it has no file to close, and registering a
> callback for it at allocation time is wasted. Registering it lazily on
> the first segment_open call avoids that. I will do it that way in the
> next version, with the callback on the reader's own context.
>
> > Note that xlogreader.h declares a new variable that makes no sense in
> > FRONTEND code. This needs an #ifdef.
>
> Ah, missed that. I will fix it.
>
> I will address the comments and post new patches soon.

Please find attached the v2 patches implementing lazy registration of
the reset callback, only when a WAL segment is opened. v2-0001 is for
HEAD and PG19. The nocfbot versions are for the back branches.

--
Bharath Rupireddy
Amazon Web Services: https://aws.amazon.com

Attachment Content-Type Size
v2-0001-Fix-WAL-segment-file-descriptor-leak-on-WAL-read-.patch application/x-patch 5.7 KB
nocfbot-v2-0001-PG18-Fix-WAL-segment-file-descriptor-leak.patch application/x-patch 7.5 KB
nocfbot-v2-0001-PG17-Fix-WAL-segment-file-descriptor-leak.patch application/x-patch 7.4 KB
nocfbot-v2-0001-PG16-Fix-WAL-segment-file-descriptor-leak.patch application/x-patch 7.3 KB
nocfbot-v2-0001-PG15-Fix-WAL-segment-file-descriptor-leak.patch application/x-patch 7.3 KB
nocfbot-v2-0001-PG14-Fix-WAL-segment-file-descriptor-leak.patch application/x-patch 7.3 KB

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message vignesh C 2026-10-01 04:47:00 Re: Proposal: Conflict log history table for Logical Replication
Previous Message Michael Paquier 2026-10-01 04:23:50 Re: Report index currently being vacuumed in pg_stat_progress_vacuum