pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
5+ messages / 3 participants
[nested] [flat]

Commits from this thread:
  2026-11-18 5dce445894 d758df2389 65efcf4576 41a8fa4811 f8b67085dd ab294dada6  Stop WAL streaming on timeline history file write failures
* pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
@ 2026-11-11 01:55  Chao Li <li.evan.chao@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Chao Li @ 2026-11-11 01:55 UTC (permalink / raw)
  To: pgsql-hackers

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.c index 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) =
^ permalink raw reply [nested|flat] 5+ messages in thread

* Re: pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
@ 2026-11-11 02:47  Fujii Masao <masao.fujii@gmail.com>
  parent: Chao Li <li.evan.chao@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Fujii Masao @ 2026-11-11 02:47 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: pgsql-hackers

On Wed, Nov 11, 2026 at 10:56 AM Chao Li <li.evan.chao@gmail.com> wrote:
> Attached is a trivial patch that checks the return value of writeTimeLineHistoryFile() and returns false on failure.

Thanks for the report and patch! LGTM.
Barring any objections, I will commit it.

Regards,

-- 
Fujii Masao






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
@ 2026-11-13 22:20  surya poondla <suryapoondla4@gmail.com>
  parent: Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: surya poondla @ 2026-11-13 22:20 UTC (permalink / raw)
  To: Chao Li <li.evan.chao@gmail.com>; +Cc: pgsql-hackers; Fujii Masao <masao.fujii@gmail.com>

Hi Chao,

Thank you for reporting the issue and fixing it. The patch looks good to
me.

Regards,
Surya Poondla

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
@ 2026-11-18 04:34  Fujii Masao <masao.fujii@gmail.com>
  parent: surya poondla <suryapoondla4@gmail.com>
  0 siblings, 1 reply; 5+ messages in thread

From: Fujii Masao @ 2026-11-18 04:34 UTC (permalink / raw)
  To: surya poondla <suryapoondla4@gmail.com>; +Cc: Chao Li <li.evan.chao@gmail.com>; pgsql-hackers

On Sat, Nov 14, 2026 at 7:21 AM surya poondla <suryapoondla4@gmail.com> wrote:
> Thank you for reporting the issue and fixing it. The patch looks good to me.

I've pushed the patch. Thanks!

Regards,

-- 
Fujii Masao






^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: pg_basebackup: check timeline history file write failures in ReceiveXlogStream()
@ 2026-11-18 05:40  Chao Li <li.evan.chao@gmail.com>
  parent: Fujii Masao <masao.fujii@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Chao Li @ 2026-11-18 05:40 UTC (permalink / raw)
  To: Fujii Masao <masao.fujii@gmail.com>; +Cc: surya poondla <suryapoondla4@gmail.com>; pgsql-hackers



> On Nov 18, 2026, at 12:34, Fujii Masao <masao.fujii@gmail.com> wrote:
> 
> On Sat, Nov 14, 2026 at 7:21 AM surya poondla <suryapoondla4@gmail.com> wrote:
>> Thank you for reporting the issue and fixing it. The patch looks good to me.
> 
> I've pushed the patch. Thanks!
> 

Hi Fujii-san, thanks a lot for pushing.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/










^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2026-11-18 05:40 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2026-11-11 01:55 pg_basebackup: check timeline history file write failures in ReceiveXlogStream() Chao Li <li.evan.chao@gmail.com>
2026-11-11 02:47 ` Fujii Masao <masao.fujii@gmail.com>
2026-11-13 22:20   ` surya poondla <suryapoondla4@gmail.com>
2026-11-18 04:34     ` Fujii Masao <masao.fujii@gmail.com>
2026-11-18 05:40       ` Chao Li <li.evan.chao@gmail.com>

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