Commit e0d97d77 authored by Heikki Linnakangas's avatar Heikki Linnakangas

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.
parent 0ff5047d
...@@ -1005,6 +1005,12 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval) ...@@ -1005,6 +1005,12 @@ LWLockWaitForVar(LWLock *lock, uint64 *valptr, uint64 oldval, uint64 *newval)
lock->tail = proc; lock->tail = proc;
lock->head = proc; lock->head = proc;
/*
* Set releaseOK, to make sure we get woken up as soon as the lock is
* released.
*/
lock->releaseOK = true;
/* Can release the mutex now */ /* Can release the mutex now */
SpinLockRelease(&lock->mutex); SpinLockRelease(&lock->mutex);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment