[PATCH] Fix TOCTOU race in ReplicationSlotsComputeRequiredLSN()
JoongHyuk Shin <sjh910805@gmail.com>
From: JoongHyuk Shin <sjh910805@gmail.com>
To: pgsql-hackers@lists.postgresql.org
Date: 2026-04-17T06:50:01Z
Lists: pgsql-hackers
Attachments
- 0001-Fix-TOCTOU-race-in-ReplicationSlotsComputeRequiredLS.patch (application/octet-stream) patch 0001
Hi, Commit 2a5225b99d7 fixed a race in ReplicationSlotsComputeRequiredXmin() where ReplicationSlotControlLock was released before the global xmin update, allowing a concurrent backend to overwrite a correct value with a stale one. ReplicationSlotsComputeRequiredLSN() has the same problem, it releases the lock before calling XLogSetReplicationSlotMinimumLSN(), so a stale minimum LSN can overwrite a correct (lower) one, potentially leading to premature WAL removal. The attached patch moves LWLockRelease() to after the LSN update, matching the xmin fix. Since 2a5225b99d7 was backpatched to all supported versions, I believe this should be as well.
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