From: Chao Li <li.evan.chao@gmail.com>
To: PostgreSQL-development <pgsql-hackers@postgresql.org>
Subject: pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
Date: Wed, 11 Nov 2026 09:55:52 +0800
Message-ID: <530B55ED-C7F7-441C-BBC0-6F3F9901E414@gmail.com> (raw)
Hi,
While reviewing patch [1], I spotted that ReceiveXlogStream() calls writeTimeLineHistoryFile() without checking its result. writeTimeLineHistoryFile() can fail for several reasons and returns false to indicate a failure. This could cause pg_basebackup and pg_receivewal to continue streaming even if the timeline history file was not successfully written.
This seems a very old problem, dating back to 9.3.
Attached is a trivial patch that checks the return value of writeTimeLineHistoryFile() and returns false on failure.
[1] https://postgr.es/m/f1743511-5fab-482e-94ec-1198ce18723e@riseup.net
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/Attachments:v1-0001-Check-timeline-history-file-write-failures-in-Rec.patch (application/octet-stream, 1.4K) download
From b0b9d029176f786aa020badef1fc1e056248d572 Mon Sep 17 00:00:00 2001
From: "Chao Li (Evan)" <lic@highgo.com>
Date: Wed, 11 Nov 2026 09:35:46 +0800
Subject: [PATCH v1] Check timeline history file write failures in
ReceiveXlogStream()
writeTimeLineHistoryFile() logs an error and returns false on failure,
but its caller ignored the return value and continued streaming. This
could let pg_receivewal or pg_basebackup report success despite a
failure to save the timeline history file.
Check the return value and stop streaming on failure, clearing the
query result before returning.
Author: Chao Li <lic@highgo.com>
---
src/bin/pg_basebackup/receivelog.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/src/bin/pg_basebackup/receivelog.c b/src/bin/pg_basebackup/receivelog.cindex 77a2b4458b3..2c51c3a474e 100644--- a/src/bin/pg_basebackup/receivelog.c+++ b/src/bin/pg_basebackup/receivelog.c@@ -557,9 +557,17 @@ ReceiveXlogStream(PGconn *conn, StreamCtl *stream)
}
/* Write the history file to disk */
- writeTimeLineHistoryFile(stream,- PQgetvalue(res, 0, 0),- PQgetvalue(res, 0, 1));+ if (!writeTimeLineHistoryFile(stream,+ PQgetvalue(res, 0, 0),+ PQgetvalue(res, 0, 1)))+ {+ /*+ * Error message has been written by+ * writeTimeLineHistoryFile()+ */+ PQclear(res);+ return false;+ }
PQclear(res);
}
--
2.50.1 (Apple Git-155)
=
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-hackers@postgresql.org
Cc: li.evan.chao@gmail.com
Subject: Re: pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
In-Reply-To: <530B55ED-C7F7-441C-BBC0-6F3F9901E414@gmail.com>
References: <530B55ED-C7F7-441C-BBC0-6F3F9901E414@gmail.com>
* 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