avoid deadlocks when working with shared repos

Summary:
Lock ordering is important. When working with shared repos, when we
aquire a shared wlock, we must also acquire the master repo's wlock to ensure
that any operations that might later grab the lock are properly ordered.

Reviewed By: quark-zju, simpkins

Differential Revision: D9613877

fbshipit-source-id: 2c3eeeea534cdf49f3bd7e94db441c3a1479a959
This commit is contained in:
Ryan McElroy 2018-09-05 03:09:53 -07:00 committed by Facebook Github Bot
parent a85cac573c
commit fee11729ac

View File

@ -1831,7 +1831,16 @@ class localrepository(object):
if self._currentlock(self._lockref) is not None:
self.ui.develwarn('"wlock" acquired after "lock"')
# if this is a shared repo and we must also lock the shared wlock
# or else we can deadlock due to lock ordering issues
srcwlock = None
srcrepo = self._getsrcrepo()
if srcrepo:
srcwlock = srcrepo.wlock()
def unlock():
if srcwlock:
srcwlock.release()
if self.dirstate.pendingparentchange():
self.dirstate.invalidate()
else: