pgsql: Fix stale-pointer problem in fast-path locking logic.

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Fix stale-pointer problem in fast-path locking logic.
Date: 2013-11-27 23:10:24
Message-ID: E1VloFU-0004LJ-Gf@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Fix stale-pointer problem in fast-path locking logic.

When acquiring a lock in fast-path mode, we must reset the locallock
object's lock and proclock fields to NULL. They are not necessarily that
way to start with, because the locallock could be left over from a failed
lock acquisition attempt earlier in the transaction. Failure to do this
led to all sorts of interesting misbehaviors when LockRelease tried to
clean up no-longer-related lock and proclock objects in shared memory.
Per report from Dan Wood.

In passing, modify LockRelease to elog not just Assert if it doesn't find
lock and proclock objects for a formerly fast-path lock, matching the code
in FastPathGetRelationLockEntry and LockRefindAndRelease. This isn't a
bug but it will help in diagnosing any future bugs in this area.

Also, modify FastPathTransferRelationLocks and FastPathGetRelationLockEntry
to break out of their loops over the fastpath array once they've found the
sole matching entry. This was inconsistently done in some search loops
and not others.

Improve assorted related comments, too.

Back-patch to 9.2 where the fast-path mechanism was introduced.

Branch
------
REL9_2_STABLE

Details
-------
http://git.postgresql.org/pg/commitdiff/024edb4543d4159c587e71fff3d6ab6a85a10beb

Modified Files
--------------
src/backend/storage/lmgr/lock.c | 83 ++++++++++++++++++++++++++-------------
src/include/storage/lock.h | 20 ++++++++--
2 files changed, 73 insertions(+), 30 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Peter Eisentraut 2013-11-28 02:54:24 pgsql: doc: Put data types in alphabetical order
Previous Message Kevin Grittner 2013-11-27 20:37:45 pgsql: Minor correction of READ COMMITTED isolation level docs.