pgsql: Fix deadlock with LWLockAcquireWithVar and LWLockWaitForVar.

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix deadlock with LWLockAcquireWithVar and LWLockWaitForVar.
Date: 2014-10-14 07:14:31
Message-ID: E1XdwJT-0004sl-Ur@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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.

Branch
------
REL9_4_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/4dbc7606cfc8188646a2e302ef5e6a5ec3c962af

Modified Files
--------------
src/backend/storage/lmgr/lwlock.c | 6 ++++++
1 file changed, 6 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Alvaro Herrera 2014-10-14 18:20:20 pgsql: pg_dump: Reduce use of global variables
Previous Message Heikki Linnakangas 2014-10-14 06:52:57 pgsql: Fix typo in docs.