Fix deadlock with LWLockAcquireWithVar and LWLockWaitForVar.
authorHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 14 Oct 2014 06:55:26 +0000 (09:55 +0300)
committerHeikki Linnakangas <heikki.linnakangas@iki.fi>
Tue, 14 Oct 2014 07:06:47 +0000 (10:06 +0300)
commite0d97d77bf0875e4d5cc7dedfe701d9999bf678c
tree7c43bbcbd2ba7448aea27e0b907821f0997c106d
parent0ff5047d52ab84dad682ad140b6992c294580eb1
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