From 69148da8fddc1b84689174c1bb2219a75304b805 Mon Sep 17 00:00:00 2001 From: Heikki Linnakangas Date: Fri, 27 Nov 2026 13:02:01 +0200 Subject: [PATCH v17 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. Discussion: https://postgr.es/m/0aac2b1a-ec0f-4bb6-a786-760e6cea4d1d@iki.fi --- 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