lock: if we fork, ensure that only the parent releases
This prevents us from having a bunch of errant worker processes all try
to release a lock if a problem occurs. (Releasing the lock more than once
is harmless; it's invoking the associated callbacks we want to avoid.)
--- a/mercurial/lock.py Thu Apr 11 14:44:22 2013 +0200
+++ b/mercurial/lock.py Thu Apr 11 13:30:27 2013 -0700
@@ -36,6 +36,7 @@
self.releasefn = releasefn
self.desc = desc
self.postrelease = []
+ self.pid = os.getpid()
self.lock()
def __del__(self):
@@ -71,7 +72,7 @@
return
if lock._host is None:
lock._host = socket.gethostname()
- lockname = '%s:%s' % (lock._host, os.getpid())
+ lockname = '%s:%s' % (lock._host, self.pid)
while not self.held:
try:
util.makelock(lockname, self.f)
@@ -133,6 +134,9 @@
self.held -= 1
elif self.held == 1:
self.held = 0
+ if os.getpid() != self.pid:
+ # we forked, and are not the parent
+ return
if self.releasefn:
self.releasefn()
try: