postgres.git / summary / log / commit / refs
commit 4dbc7606cfc8188646a2e302ef5e6a5ec3c962af
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: Tue Oct 14 06:55:26 2014 +0000
First released in: 9.5.0, 9.4.0
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.
src/backend/storage/lmgr/lwlock.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/backend/storage/lmgr/lwlock.c b/src/backend/storage/lmgr/lwlock.c
index 5453549a792..1607bc9e536 100644
--- a/src/backend/storage/lmgr/lwlock.c
+++ b/src/backend/storage/lmgr/lwlock.c
@@ -976,6 +976,12 @@ LWLockWaitForVar(LWLock *l, uint64 *valptr, uint64 oldval, uint64 *newval)
lock->tail = 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 */
SpinLockRelease(&lock->mutex);
[parent: 79ec6e399f13]