]> granicus.if.org Git - postgresql/commit
Avoid potential deadlock in InitCatCachePhase2().
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Mar 2011 17:01:17 +0000 (13:01 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Mar 2011 17:01:17 +0000 (13:01 -0400)
commitcf73547075f3632da3beef345eb50646bf142edf
tree929eb6ed803845b385aefcce493e64dfef11f2df
parent4c1a9ee665761906c774bb2c5bcaa61ae7d6aa87
Avoid potential deadlock in InitCatCachePhase2().

Opening a catcache's index could require reading from that cache's own
catalog, which of course would acquire AccessShareLock on the catalog.
So the original coding here risks locking index before heap, which could
deadlock against another backend trying to get exclusive locks in the
normal order.  Because InitCatCachePhase2 is only called when a backend
has to start up without a relcache init file, the deadlock was seldom seen
in the field.  (And by the same token, there's no need to worry about any
performance disadvantage; so not much point in trying to distinguish
exactly which catalogs have the risk.)

Bug report, diagnosis, and patch by Nikhil Sontakke.  Additional commentary
by me.  Back-patch to all supported branches.
src/backend/utils/cache/catcache.c
src/backend/utils/cache/relcache.c