Re: Fix the race condition for updating slot minimum LSN
surya poondla <suryapoondla4@gmail.com>
From: surya poondla <suryapoondla4@gmail.com>
To: "Zhijie Hou (Fujitsu)" <houzj.fnst@fujitsu.com>
Cc: Postgres hackers <pgsql-hackers@lists.postgresql.org>, "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>,
Amit Kapila <amit.kapila16@gmail.com>
Date: 2026-04-14T23:25:44Z
Lists: pgsql-hackers
Hi Hou zj, Thanks for the patch. The fix looks correct and the approach mirrors the one taken in commit 2a5225b for the xmin race. I have a question about copy_replication_slot() in slotfuncs.c, the restart_lsn is written under only the spinlock, followed by ReplicationSlotsComputeRequiredLSN() the same pattern that this patch fixes. Could this path be affected by the same race? Looking at the code, I think it is safe because create_logical_replication_slot() is called with src_restart_lsn which is always a valid LSN (if not valid, an error is thrown). Inside CreateInitDecodingContext(), since restart_lsn is valid, ReplicationSlotReserveWal() is skipped and the slot's restart_lsn is set directly to src_restart_lsn. So by the time the write of the slot happens, the destination slot already has a valid non-zero restart_lsn, the InvalidXLogRecPtr window never exists. Additionally, line the code errors out if copy_restart_lsn < src_restart_lsn, so the write never moves restart_lsn backward, meaning a concurrent scanner will always see a valid LSN and never skip this slot. If that reasoning is correct, a comment near the ReplicationSlotsComputeRequiredLSN() in copy_replication_slot() explaining why it does not need the same protection would help future readers. Regards, Surya Poondla
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
Fix a race condition in updating procArray->replication_slot_xmin.
- 2a5225b99d76 19 (unreleased) cited