patch: fix race in SSI's CheckTargetForConflictsIn - Mailing list pgsql-hackers

From Dan Ports
Subject patch: fix race in SSI's CheckTargetForConflictsIn
Date
Msg-id 20110505014057.GR85173@csail.mit.edu
Whole thread Raw
Responses Re: patch: fix race in SSI's CheckTargetForConflictsIn  ("Kevin Grittner" <Kevin.Grittner@wicourts.gov>)
List pgsql-hackers
While running some benchmarks to test SSI performance, I found a race
condition that's capable of causing a segfault. A patch is attached.

The bug is in CheckTargetForConflictsIn, which scans the list of SIREAD
locks on a lock target when it's modified. There's an optimization in
there where the writing transaction will remove a SIREAD lock that it
holds itself, because it's being replaced with a (stronger) write lock.
To do that, it needs to drop its shared lwlocks and reacquire them in
exclusive mode. The existing code deals with concurrent modifications
in that interval by redoing checks. However, it misses the case where
some other transaction removes all remaining locks on the target, and
proceeds to remove the lock target itself.

The attached patch fixes this by deferring the SIREAD lock removal
until the end of the function. At that point, there isn't any need to
worry about concurrent updates to the target's lock list. The resulting
code is also simpler.

Dan

--
Dan R. K. Ports              MIT CSAIL                http://drkp.net/

Attachment

pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Some surprising precedence behavior in PG's grammar
Next
From: Tatsuo Ishii
Date:
Subject: Enhancing online recovery in SR mode