From 3de4dfbea1d12fd084e24e431fb2b0986efa3e12 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 27 Nov 2026 13:02:01 +0200 Subject: [PATCH v16 7/8] Hold spinlock while clearing MyProc->pid on backend exit That's what auxiliary proc exit did already. This makes no difference now, but allows the next commit to atomically check that a PGPROC entry is in use by given pid, and set an interrupt bit on its PGPROC entry, without risk that the process exits and the entry is reused for another process in the meanwhile. --- src/backend/storage/lmgr/proc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/backend/storage/lmgr/proc.c b/src/backend/storage/lmgr/proc.c index d4a830181d8..f9175c72cc1 100644 --- a/src/backend/storage/lmgr/proc.c +++ b/src/backend/storage/lmgr/proc.c @@ -1051,12 +1051,13 @@ ProcKill(int code, Datum arg) MyProc = NULL; MyProcNumber = INVALID_PROC_NUMBER; + SpinLockAcquire(&ProcGlobal->freeProcsLock); + /* Mark the proc no longer in use */ proc->pid = 0; proc->vxid.procNumber = INVALID_PROC_NUMBER; proc->vxid.lxid = InvalidTransactionId; - SpinLockAcquire(&ProcGlobal->freeProcsLock); if (push_leader) { /* Return leader PGPROC (and semaphore) to appropriate freelist */ -- 2.54.0