Assertion failure in GetSnapshotDataReuse() during promotion

From: Fujii Masao <masao(dot)fujii(at)gmail(dot)com>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Assertion failure in GetSnapshotDataReuse() during promotion
Date: 2026-12-02 13:23:53
Message-ID: CAHGQGwEduAjaWsb239RaMOkhVDT_XeX885Os_G=mEB7Wr9Ot0g@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi,

Buildfarm animal sidewinder reported an assertion failure in
GetSnapshotDataReuse() while running 061_recovery_target_prefetch.pl [1].

The problem seems to be that xactCompletionCount was not incremented when
snapshot management switched from KnownAssignedXids to ProcArray at
the end of recovery. So, an older snapshot taken from KnownAssignedXids could
be incorrectly reused because the counter had not changed. If the backend
then took a new transaction snapshot, the "TransactionXmin <= RecentXmin"
assertion failed.

Attached 0001 fixes this by advancing the counter at the transition.
Also it advances the counter when initializing latestCompletedXid,
which could otherwise leave cached snapshots with a stale xmax.

Patch 0002 provides a reproducer using injection points. It reproduces
the assertion failure without 0001 and passes with it. Unfortunately,
the test is somewhat timing-sensitive, so you may need to run it
several times to reproduce the failure.

Thoughts?

Regards,

[1] https://buildfarm.postgresql.org/cgi-bin/show_log.pl?nm=sidewinder&dt=2026-12-02%2000%3A38%3A12

--
Fujii Masao

Attachment Content-Type Size
v1-0001-Fix-snapshot-cache-invalidation-at-the-end-of-rec.patch application/octet-stream 3.0 KB
v1-0002-Test-snapshot-cache-invalidation-during-promotion.patch application/octet-stream 4.5 KB
nocfbot-v1-0001-Fix-snapshot-cache-invalidation-at-the-end-of-rec-v16-v15.patch application/octet-stream 2.9 KB

Browse pgsql-hackers by date

  From Date Subject
Next Message Rui Zhao 2026-12-02 13:28:31 Re: memory leak in bounded sorts
Previous Message Matheus Alcantara 2026-12-02 12:56:39 Re: [PATCH v1] Fix for Bug#19724 - ALTER TYPE ... ALTER ATTRIBUTE triggers internal error for base type of domain with check