Re: WAL segment file descriptor leak on read errors can PANIC the server - Mailing list pgsql-hackers

From Alexandre Felipe
Subject Re: WAL segment file descriptor leak on read errors can PANIC the server
Date
Msg-id CAE8JnxN7vEYLuMksXYSrq_tGnQrEGsp1DXCYLVGg-O3yq62L-w@mail.gmail.com
Whole thread
In response to Re: WAL segment file descriptor leak on read errors can PANIC the server  (Bertrand Drouvot <bertranddrouvot.pg@gmail.com>)
Responses Re: WAL segment file descriptor leak on read errors can PANIC the server
List pgsql-hackers

On Mon, Oct 5, 2026 at 10:20 AM Bertrand Drouvot <bertranddrouvot.pg@gmail.com> wrote:
Worth mentioning that this is intended for descriptors not managed by another
cleanup mechanism, such as those returned by BasicOpenFile()?  Otherwise, using
it with OpenTransientFile() could result in segment_close() being called with a
stale descriptor.

BasicOpenFile() called repeatedly will accumulate stale descriptors indefinitely.


int
BasicOpenFile(const char *fileName, int fileFlags)
{
  return BasicOpenFilePerm(fileName, fileFlags, pg_file_create_mode);
}

int
BasicOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode)

{

    int         fd;

    fd = open(fileName, fileFlags & ~PG_O_DIRECT, fileMode);

    if (fd >= 0)

    {

        return fd;              /* success! */


While
PathNameOpenFilePerm(const char *fileName, int fileFlags, mode_t fileMode)

Is tracked by a LRU list, and the number of open files in that list is capped.

pgsql-hackers by date:

Previous
From: Ashutosh Sharma
Date:
Subject: Re: Persist slot invalidations before publishing them
Next
From: "Hayato Kuroda (Fujitsu)"
Date:
Subject: RE: Bug in logical decoding with DDL and subtransactions