Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 4dbc760

Browse files
committed
Fix deadlock with LWLockAcquireWithVar and LWLockWaitForVar.
LWLockRelease should release all backends waiting with LWLockWaitForVar, even when another backend has already been woken up to acquire the lock, i.e. when releaseOK is false. LWLockWaitForVar can return as soon as the protected value changes, even if the other backend will acquire the lock. Fix that by resetting releaseOK to true in LWLockWaitForVar, whenever adding itself to the wait queue. This should fix the bug reported by MauMau, where the system occasionally hangs when there is a lot of concurrent WAL activity and a checkpoint. Backpatch to 9.4, where this code was added.
1 parent 79ec6e3 commit 4dbc760

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/backend/storage/lmgr/lwlock.c

+6
Original file line numberDiff line numberDiff line change
@@ -976,6 +976,12 @@ LWLockWaitForVar(LWLock *l, uint64 *valptr, uint64 oldval, uint64 *newval)
976976
lock->tail = proc;
977977
lock->head = proc;
978978

979+
/*
980+
* Set releaseOK, to make sure we get woken up as soon as the lock is
981+
* released.
982+
*/
983+
lock->releaseOK = true;
984+
979985
/* Can release the mutex now */
980986
SpinLockRelease(&lock->mutex);
981987

0 commit comments

Comments
 (0)