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

From: Alexandre Felipe <o(dot)alexandre(dot)felipe(at)gmail(dot)com>
To: Bertrand Drouvot <bertranddrouvot(dot)pg(at)gmail(dot)com>
Cc: Michael Paquier <michael(at)paquier(dot)xyz>, Bharath Rupireddy <bharath(dot)rupireddyforpostgres(at)gmail(dot)com>, 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-05 09:59:16
Message-ID: CAE8JnxN7vEYLuMksXYSrq_tGnQrEGsp1DXCYLVGg-O3yq62L-w@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Mon, Oct 5, 2026 at 10:20 AM Bertrand Drouvot <
bertranddrouvot(dot)pg(at)gmail(dot)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.

I wrote about a potential relation with this before in
https://www.postgresql.org/message-id/CAE8JnxOyYyv6m%3DMz%2BNwQb%3DQj6yFkXD2a%2Bn%3D%2BNes6mhmH6L5PoQ%40mail.gmail.com

Regards,
Alexandre

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Hayato Kuroda (Fujitsu) 2026-10-05 10:13:03 RE: Bug in logical decoding with DDL and subtransactions
Previous Message Ashutosh Sharma 2026-10-05 09:52:53 Re: Persist slot invalidations before publishing them