pgsql: Fix deadlock at startup, if max_prepared_transactions is too sma

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix deadlock at startup, if max_prepared_transactions is too sma
Date: 2015-04-23 18:40:56
Message-ID: E1YlM3U-0001XO-T5@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix deadlock at startup, if max_prepared_transactions is too small.

When the startup process recovers transactions by scanning pg_twophase
directory, it should clear MyLockedGxact after it's done processing each
transaction. Like we do during normal operation, at PREPARE TRANSACTION.
Otherwise, if the startup process exits due to an error, it will try to
clear the locking_backend field of the last recovered transaction. That's
usually harmless, but if the error happens in MarkAsPreparing, while
holding TwoPhaseStateLock, the shmem-exit hook will try to acquire
TwoPhaseStateLock again, and deadlock with itself.

This fixes bug #13128 reported by Grant McAlister. The bug was introduced
by commit bb38fb0d, so backpatch to all supported versions like that
commit.

Branch
------
REL9_0_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/223a946804aafeefc6cb26de276776eec576547d

Modified Files
--------------
src/backend/access/transam/twophase.c | 6 ++++++
1 file changed, 6 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2015-04-23 18:47:50 Re: pgsql: Improve speed of make check-world
Previous Message Peter Eisentraut 2015-04-23 17:10:35 pgsql: Fix shell error on Solaris