Re: ReplicationSlotRelease() crashes when the instance is in the single user mode - Mailing list pgsql-hackers

From David G. Johnston
Subject Re: ReplicationSlotRelease() crashes when the instance is in the single user mode
Date
Msg-id CAKFQuwaUgYHhZiFkMrPMraiXu2NTCY2SUC_CdYNQZoqhxdw1hw@mail.gmail.com
Whole thread Raw
In response to ReplicationSlotRelease() crashes when the instance is in the single user mode  ("Hayato Kuroda (Fujitsu)" <kuroda.hayato@fujitsu.com>)
List 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.

pgsql-hackers by date:

Previous
From: jian he
Date:
Subject: Re: Non-text mode for pg_dumpall
Next
From: "David G. Johnston"
Date:
Subject: Re: UUID v7