Spinlock can be released twice in procsignal.c - Mailing list pgsql-hackers

From Maksim.Melnikov
Subject Spinlock can be released twice in procsignal.c
Date
Msg-id dca47527-2d8b-4e3b-b5a0-e2deb73371a4@postgrespro.ru
Whole thread Raw
Responses Re: Spinlock can be released twice in procsignal.c
List pgsql-hackers

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.

Attachment

pgsql-hackers by date:

Previous
From: Masahiko Sawada
Date:
Subject: Re: Restrict copying of invalidated replication slots
Next
From: Ekaterina Sokolova
Date:
Subject: Proposal: Limitations of palloc inside checkpointer