Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit25576be

Browse files
committed
Guard against spurious signals in LockBufferForCleanup.
When LockBufferForCleanup() has to wait for getting a cleanup lock on abuffer it does so by setting a flag in the buffer header and then waitfor other backends to signal it using ProcWaitForSignal().Unfortunately LockBufferForCleanup() missed that ProcWaitForSignal() canreturn for other reasons than the signal it is hoping for. If such aspurious signal arrives the wait flags on the buffer header will stillbe set. That then triggers "ERROR: multiple backends attempting to waitfor pincount 1".The fix is simple, unset the flag if still set when retrying. Thatimplies an additional spinlock acquisition/release, but that's unlikelyto matter given the cost of waiting for a cleanup lock. Alternativelyit'd have been possible to move responsibility for maintaining therelevant flag to the waiter all together, but that might have hadnegative consequences due to possible floods of signals. Besides beingmore invasive.This looks to be a very longstanding bug. The relevant code inLockBufferForCleanup() hasn't changed materially since its introductionand ProcWaitForSignal() was documented to return for unrelated reasonssince 8.2. The master only patch series removing ImmediateInterruptOKmade it much easier to hit though, as ProcSendSignal/ProcWaitForSignalnow uses a latch shared with other tasks.Per discussion with Kevin Grittner, Tom Lane and me.Backpatch to all supported branches.Discussion: 11553.1423805224@sss.pgh.pa.us
1 parent7052abb commit25576be

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

‎src/backend/storage/buffer/bufmgr.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2506,6 +2506,20 @@ LockBufferForCleanup(Buffer buffer)
25062506
else
25072507
ProcWaitForSignal();
25082508

2509+
/*
2510+
* Remove flag marking us as waiter. Normally this will not be set
2511+
* anymore, but ProcWaitForSignal() can return for other signals as
2512+
* well. We take care to only reset the flag if we're the waiter, as
2513+
* theoretically another backend could have started waiting. That's
2514+
* impossible with the current usages due to table level locking, but
2515+
* better be safe.
2516+
*/
2517+
LockBufHdr(bufHdr);
2518+
if ((bufHdr->flags&BM_PIN_COUNT_WAITER)!=0&&
2519+
bufHdr->wait_backend_pid==MyProcPid)
2520+
bufHdr->flags &= ~BM_PIN_COUNT_WAITER;
2521+
UnlockBufHdr(bufHdr);
2522+
25092523
PinCountWaitBuf=NULL;
25102524
/* Loop back and try again */
25112525
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp