Re: ReplicationSlotRelease() crashes when the instance is in the single user mode
David G. Johnston <david.g.johnston@gmail.com>
From: "David G. Johnston" <david.g.johnston@gmail.com>
To: "Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>
Cc: "pgsql-hackers@lists.postgresql.org" <pgsql-hackers@lists.postgresql.org>
Date: 2025-02-18T06:49:45Z
Lists: pgsql-hackers
On Monday, February 17, 2025, Hayato Kuroda (Fujitsu) < kuroda.hayato@fujitsu.com> wrote: > > backend> SELECT pg_create_physical_replication_slot(slot_name := > 'physical_slot', immediately_reserve := true); Since this function releases the slot when it returns, re-acquisition, even by the same backend, must always re-associate MyProcPid to the named slot. > > [1]: > ``` > --- a/src/backend/replication/slot.c > +++ b/src/backend/replication/slot.c > @@ -599,7 +599,7 @@ retry: > SpinLockRelease(&s->mutex); > } > else > - active_pid = MyProcPid; > + s->active_pid = active_pid = MyProcPid; > LWLockRelease(ReplicationSlotControlLock); > > /* > ``` > This, but you cannot modify the slot without holding the spinlock. I’d probably add an assert that the existing state of s->active_pid is either 0 or MyProcPid already. In single-user mode it mustn’t, really cannot, be anything else. But the failure here is because the SQL function does a slot release; there are probably other reasonable paths where the assignment of MyProcPid during slot creation is retained and encountered during a subsequent slot acquire. David J.
Commits
-
Fix assertion failure with replication slot release in single-user mode
- 8ed079cad824 13.23 landed
- 32d388d00f9f 14.20 landed
- 818be9b73c94 15.15 landed
- fea1cc3f75ff 16.11 landed
- 07a302387176 17.7 landed
- ea1c6b0b0aec 18.0 landed
- 1f2e51e3c7c2 19 (unreleased) landed