| From: | Michael Paquier <michael(at)paquier(dot)xyz> |
|---|---|
| To: | Raja Sai pranav <rajasaipranav0(at)gmail(dot)com> |
| Cc: | pgsql-bugs(at)lists(dot)postgresql(dot)org, idrissaajalloh(at)gmail(dot)com |
| Subject: | Re: BUG #19890: pg_receivewal advances past a truncated LZ4 WAL segment |
| Date: | 2026-11-25 06:01:23 |
| Message-ID: | awZ5s_7yQNepf0S8@paquier.xyz |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
On Fri, Nov 20, 2026 at 10:31:25PM -0800, Raja Sai pranav wrote:
> FindStreamingStart() decompresses each completed .lz4 segment and checks
> only that it yields exactly one segment of data. It never checks that the
> LZ4 frame ended. LZ4F_decompress() returns 0 only once a frame is fully
> decoded, so the patch records whether the last call returned 0. If it
> didn't, the segment is skipped with a warning ("compressed segment file ...
> is truncated, skipping"), the same way a segment of the wrong size is
> skipped today.
The only way to see this failure would be a segment that is not
fsync-ed properly, leading to something cut earlier than it should.
pg_receivewal *without* --no-sync, taken in isolation, already ensures
that this will never happen: we make sure that segments are flushed in
full, and there are a bunch of safeguards in favor of that. That's
not an option one should use in production environments, or one likes
data corruption.
One could argue about external tools that have the idea to use content
checksums: if a frame includes one, this could offer some extra sanity
check when pg_receivewal looks for the streaming start LSN. I don't
think that we should add content checksums in pg_receivewal, as the
CRC32s in the WAL records provide a similar protection on replay. (Or
perhaps we actually should do that, so as the streaming start would
skip incorrect segments? That would be a HEAD-only thing anyway.)
So, I could see the argument of the extra check as a defense in depth
measure, at least. We document that in FindStreamingStart() that we
accept segments from external sources, and it would be possible that
these are considered correct under pg_receivewal but not under what
lz4 thinks is correct, so I'd tend to think that a backpatch down to
v15 (where this code has been added) is an acceptable thing to do
here.
> The patch adds a test to src/bin/pg_basebackup/t/
> https://www.google.com/url?q=http://020_pg_receivewal.pl&source=gmail&ust=1795329083836000&sa=E.
> It copies a completed .lz4 segment into a new directory, cuts off the
> 4-byte end mark of the frame, and puts a full-size uncompressed segment
> just before it, as your script does. pg_receivewal must then warn and
> restart at the start of the cut segment. Without the fix it restarts at the
> next segment and the test fails; with it, the pg_basebackup TAP suite
> passes. The patch applies to REL_18_STABLE and REL_19_STABLE.
I don't buy that the suggested test is worth the cycles spent on.
Nice to reproduce the problem by tweaking what's on disk, but not
needed IMO.
Any thoughts or comments from others?
--
Michael
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Fujii Masao | 2026-11-25 07:47:05 | Re: Lost walsender wakeup stalls synchronous commits until the standby's next reply (16+) |
| Previous Message | Michael Paquier | 2026-11-25 05:07:04 | Re: BUG #18754: Logical replication cannot restart if client sent a copyDone |