pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Fix file descriptor leakages in pg_waldump.
Date: Wed, 25 Mar 2026 22:37:40 +0000
Message-ID: <E1w5Wr5-001Rpa-2a@gemulon.postgresql.org> (raw)

Fix file descriptor leakages in pg_waldump.

TarWALDumpCloseSegment was of the opinion that it didn't need to
do anything.  It was mistaken: it has to close the open file if
any, because nothing else will, leading to a descriptor leak.

In addition, we failed to ensure that any file being read by the
XLogReader machinery gets closed before the atexit callback tries to
cleanup the temporary directory holding spilled WAL files.  While the
file would have been closed already in case of a success exit, this
doesn't happen in case of pg_fatal() exits.  The least messy way
to fix that is to move the atexit function into pg_waldump.c,
where it has easier access to the XLogReaderState pointer and to
WALDumpCloseSegment.

These FD leakages are pretty insignificant on Unix-ish platforms,
but they're a bug on Windows, because they prevent successful cleanup
of the temporary directory for extracted WAL files.  (Windows can't
delete a directory that holds a deleted-but-still-open file.)
This is visible in occasional buildfarm failures.

This code's all new as of commit b15c15139, so no need for back-patch.

Discussion: https://postgr.es/m/374225.1774459521@sss.pgh.pa.us

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/03b1e30e7aa5c0d83514db4156cfc80632f50493

Modified Files
--------------
src/bin/pg_waldump/archive_waldump.c | 26 +++------------------
src/bin/pg_waldump/pg_waldump.c      | 44 +++++++++++++++++++++++++++++++++---
2 files changed, 44 insertions(+), 26 deletions(-)



Message-ID: <E1w5Wr5-001Rpa-2a@gemulon.postgresql.org>
Permalink:  ../E1w5Wr5-001Rpa-2a@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1w5Wr5-001Rpa-2a@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Fix file descriptor leakages in pg_waldump.
  In-Reply-To: <E1w5Wr5-001Rpa-2a@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox