[PATCH 1 of 2] lock: if we fork, ensure that only the parent releases
Bryan O'Sullivan
bos at serpentine.com
Thu Apr 11 20:30:48 UTC 2013
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1365712227 25200
# Thu Apr 11 13:30:27 2013 -0700
# Node ID 3d2ead77daf3f2ec8a49fa4baf0cfb69e20fbaa6
# Parent e798e7cc19d8658e40c3c25264213251f8e8b2fc
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.)
diff --git a/mercurial/lock.py b/mercurial/lock.py
--- a/mercurial/lock.py
+++ b/mercurial/lock.py
@@ -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:
More information about the Mercurial-devel
mailing list