Incorrect errno used in OpenWalSummaryFile()

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: Postgres hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Incorrect errno used in OpenWalSummaryFile()
Date: 2026-02-02 03:54:26
Message-ID: aYAf8qDHbpBZ3Rml@paquier.xyz
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi all,

While looking at walsummary.c for a different thread, I have bumped
into this code:
OpenWalSummaryFile(WalSummaryFile *ws, bool missing_ok)
[...]
file = PathNameOpenFile(path, O_RDONLY);
if (file < 0 && (errno != EEXIST || !missing_ok))
ereport(ERROR,
(errcode_for_file_access(),
errmsg("could not open file \"%s\": %m", path)));

And it seems to me that this EEXIST should be an ENOENT? The top of
the function also documents that we want to handle an error when a
summary file does not exist. The comment makes sense to me, not the
code.

It's also worth noting that this function has two callers, both use
missing_ok = false, meaning that the errno check does not really
matter today. If someone plays with this code on HEAD or the
back-branches and decides to introduce a missing_ok=true call, it
could matter, so I'd rather not change this function signature.

This issue has been mentioned here as well, I've just bumped into it
independently a few hours ago:
https://www.postgresql.org/message-id/tencent_1CA40FCC21C1C770712BC089@qq.com

Regards,
--
Michael

Attachment Content-Type Size
wal-summary-errno.patch text/plain 563 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message wenhui qiu 2026-02-02 03:58:02 Re: Non-committer reviews: is it helpful?
Previous Message Michael Paquier 2026-02-02 03:34:03 Re: [PATCH] Fix error message in RemoveWalSummaryIfOlderThan to indicate file removal failure