Re: Issue with the PRNG used by Postgres - Mailing list pgsql-hackers

From Alexander Lakhin
Subject Re: Issue with the PRNG used by Postgres
Date
Msg-id 284660e9-e930-963d-71f6-ca693f04dac0@gmail.com
Whole thread Raw
In response to Re: Issue with the PRNG used by Postgres  (Alexander Lakhin <exclusion@gmail.com>)
List pgsql-hackers
12.04.2024 08:05, Alexander Lakhin wrote:
> 2024-04-12 05:00:17.981 UTC [762336] PANIC:  stuck spinlock detected at WaitBufHdrUnlocked, bufmgr.c:5726
>

It looks like that spinlock issue caused by a race condition/deadlock.
What I see when the test fails is:
A client backend executing "DROP DATABASE conflict_db" performs
dropdb() -> DropDatabaseBuffers() -> InvalidateBuffer()
At the same time, bgwriter performs (for the same buffer):
BgBufferSync() -> SyncOneBuffer()

When InvalidateBuffer() is called, the buffer refcount is zero,
then bgwriter pins the buffer, thus increases refcount;
InvalidateBuffer() gets into the retry loop;
bgwriter calls UnpinBuffer() -> UnpinBufferNoOwner() ->
   WaitBufHdrUnlocked(), which waits for !BM_LOCKED state,
while InvalidateBuffer() waits for the buffer refcount decrease.

As it turns out, it's not related to spinlocks' specifics or PRNG, just a
serendipitous find.

Best regards,
Alexander



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: Issue with the PRNG used by Postgres
Next
From: Andres Freund
Date:
Subject: Re: Security lessons from liblzma - libsystemd