Cyclic dependency checker: don't give up token in common case.

The way the code was written, we'd give up our token, detect a cyclic
dependency, and then try to get our token back before exiting.  Even
with -j1, the temporary token release allowed any parent up the tree to
continue running jobs, so it would take an arbitrary amount of time
before we could exit (and report an error code to the parent).

There was no visible symptom of this except that, with -j1, t/355-deps-cyclic
would not finish until some of the later tests finished, which was
surprising.

To fix it, let's just check for a cyclic dependency first, then release
the token only once we're sure things are sane.
This commit is contained in:
Avery Pennarun 2018-11-13 06:54:31 -05:00
commit bb80118298
3 changed files with 19 additions and 15 deletions

View file

@ -348,8 +348,14 @@ class Lock:
if self.lockfile is not None:
os.close(self.lockfile)
def trylock(self):
def check(self):
assert(not self.owned)
if str(self.fid) in vars.get_locks():
# Lock already held by parent: cyclic dependence
raise CyclicDependencyError()
def trylock(self):
self.check()
try:
fcntl.lockf(self.lockfile, fcntl.LOCK_EX|fcntl.LOCK_NB, 0, 0)
except IOError, e:
@ -361,10 +367,7 @@ class Lock:
self.owned = True
def waitlock(self):
assert(not self.owned)
if str(self.fid) in vars.get_locks():
# Lock already held by parent: cyclic dependence
raise CyclicDependencyError()
self.check()
fcntl.lockf(self.lockfile, fcntl.LOCK_EX, 0, 0)
self.owned = True