Re: [PATCH v2] Fix exported snapshot xmin handoff race

Поиск
Список
Период
Сортировка
Искать

Re: [PATCH v2] Fix exported snapshot xmin handoff race

От:
"chee.wooson" <chee.wooson@gmail.com>
Дата:
Вложения:
Hi,

Attached is v2.

Sorry that v1 was a bit noisy.  This was my first PostgreSQL patch
submission, and I sent the patch series inline without realizing how much
it would expand in the archives.  This version is attached as a single
patch.

Changes since v1:

- simplified the fix to take ProcArrayLock exclusively in
  ProcArrayInstallImportedXmin();
- dropped the PGPROC xmin-export state machine;
- squashed the reproducer and fix into one patch;
- adjusted the TAP test to match the exclusive-lock approach.

The race is that SET TRANSACTION SNAPSHOT can install the imported xmin
while VACUUM is already in the middle of ComputeXidHorizons(), because
both paths currently hold ProcArrayLock in shared mode.  VACUUM can then
miss both the importer's newly installed xmin and the source transaction's
xmin, and compute a horizon that is too new.

The attached patch changes ProcArrayInstallImportedXmin() to acquire
ProcArrayLock exclusively.  This serializes exported-snapshot import with
horizon computation.  The patch also adds an injection-point TAP test that
pauses VACUUM inside ComputeXidHorizons(), starts SET TRANSACTION SNAPSHOT
concurrently, and verifies that the importer waits for ProcArrayLock before
the imported snapshot is allowed to protect the deleted tuple.

Validation:

- meson test -C build --suite setup --print-errorlogs
- meson test -C build test_misc/015_export_snapshot --no-rebuild
  --print-errorlogs

The new test passes with the fix, with 3 subtests passed.  I also verified
that the patch applies cleanly to current master.

Regards,
Chee

Re: [PATCH v2] Fix exported snapshot xmin handoff race

От:
Peter Geoghegan <pg@bowt.ie>
Дата:
On Thu, Jul 30, 2026 at 12:25 AM chee.wooson  wrote:
> Attached is v2.

Are you aware that there are 2 other known bugs with pending fixes
that involve snapshot import/export? Both of which were reported very
recently?

See:

https://postgr.es/m/CAH2-WzmHVeYY=pjz9x8DhhxVjXHX0pvoQ-MdiB1Tt6=o2GTiKg@mail.gmail.com

and:

https://postgr.es/m/QpAansP4iVg_ttSs9x81PFAptL2sqR3AS06u8Jksm3_bHJvUwQjHOocRajbxBc3iiLdf9ZMC6gtXjZsxdxvOmqp98hLZcZuWyBDuQxS6uZc=@scottray.io

--
Peter Geoghegan


FAQ