Spinlock can be released twice in procsignal.c

Maksim.Melnikov <m.melnikov@postgrespro.ru>

From: "Maksim.Melnikov" <m.melnikov@postgrespro.ru>
To: pgsql-hackers@lists.postgresql.org
Date: 2025-02-25T19:34:32Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. Fix possible double-release of spinlock in procsignal.c

Attachments

Hi, it seems we can release spinlock twice in 
/src/backend/storage/ipc/procsignal.c file, method ProcSignalInit.

void
ProcSignalInit(bool cancel_key_valid, int32 cancel_key)
{
     ProcSignalSlot *slot;
     uint64        barrier_generation;

..............................................................................

     slot = &ProcSignal->psh_slot[MyProcNumber];

     /* sanity check */
     SpinLockAcquire(&slot->pss_mutex);
     if (pg_atomic_read_u32(&slot->pss_pid) != 0)
     {
*SpinLockRelease(&slot->pss_mutex);*
         elog(LOG, "process %d taking over ProcSignal slot %d, but it's 
not empty",
              MyProcPid, MyProcNumber);
     }

     /* Clear out any leftover signal reasons */
     MemSet(slot->pss_signalFlags, 0, NUM_PROCSIGNALS * 
sizeof(sig_atomic_t));

......................

     slot->pss_cancel_key_valid = cancel_key_valid;
     slot->pss_cancel_key = cancel_key;
     pg_atomic_write_u32(&slot->pss_pid, MyProcPid);

*SpinLockRelease(&slot->pss_mutex);*


First in the if clause, second near the end of function. Such behavior 
can lead to unpredictable concurrent issues.

In applied patch I removed spinlock release in if clause.