From: | "Maksim(dot)Melnikov" <m(dot)melnikov(at)postgrespro(dot)ru> |
---|---|
To: | pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Spinlock can be released twice in procsignal.c |
Date: | 2025-02-25 19:34:32 |
Message-ID: | dca47527-2d8b-4e3b-b5a0-e2deb73371a4@postgrespro.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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 | Content-Type | Size |
---|---|---|
0001-Spinlock-can-be-released-twice-in-procsignal.c.patch | text/x-patch | 842 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Ekaterina Sokolova | 2025-02-25 19:44:33 | Proposal: Limitations of palloc inside checkpointer |
Previous Message | Masahiko Sawada | 2025-02-25 18:58:39 | Re: Restrict copying of invalidated replication slots |