Hi hackers, I think that pgstat_reset_replslot() is missing LWLock protection. Indeed, we don't have any guarantee that the slot is active (then preventing it to be dropped/recreated) when this function is executed.
Attached a patch to add the missing protection. Regards, -- Bertrand Drouvot PostgreSQL Contributors Team RDS Open Source Databases Amazon Web Services: https://aws.amazon.com
>From 26007012272631a6d1024c143c8dd3eed9430c03 Mon Sep 17 00:00:00 2001 From: Bertrand Drouvot <bertranddrouvot...@gmail.com> Date: Fri, 1 Mar 2024 10:04:17 +0000 Subject: [PATCH v1] Adding LWLock protection in pgstat_reset_replslot() pgstat_reset_replslot() is missing a LWLock protection as we don't have any guarantee that the slot is active (then preventing it to be dropped/recreated) when this function is executed. --- src/backend/utils/activity/pgstat_replslot.c | 4 ++++ 1 file changed, 4 insertions(+) 100.0% src/backend/utils/activity/ diff --git a/src/backend/utils/activity/pgstat_replslot.c b/src/backend/utils/activity/pgstat_replslot.c index 70cabf2881..a113e1c486 100644 --- a/src/backend/utils/activity/pgstat_replslot.c +++ b/src/backend/utils/activity/pgstat_replslot.c @@ -46,6 +46,8 @@ pgstat_reset_replslot(const char *name) Assert(name != NULL); + LWLockAcquire(ReplicationSlotControlLock, LW_SHARED); + /* Check if the slot exits with the given name. */ slot = SearchNamedReplicationSlot(name, true); @@ -65,6 +67,8 @@ pgstat_reset_replslot(const char *name) /* reset this one entry */ pgstat_reset(PGSTAT_KIND_REPLSLOT, InvalidOid, ReplicationSlotIndex(slot)); + + LWLockRelease(ReplicationSlotControlLock); } /* -- 2.34.1