Commit 4f44e311 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Merge branch 'stable-2.5' into devel-2.5

* stable-2.5:
  jqueue: Fix epylint errors introduced in 37d76f1e


  jqueue: Fix deadlock between job queue and dependency manager
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parents df5a5730 1316ebc2
......@@ -1447,28 +1447,39 @@ class _JobDependencyManager:
" not one of '%s' as required" %
(dep_job_id, status, utils.CommaJoin(dep_status)))
@locking.ssynchronized(_LOCK)
def _RemoveEmptyWaitersUnlocked(self):
"""Remove all jobs without actual waiters.
"""
for job_id in [job_id for (job_id, waiters) in self._waiters.items()
if not waiters]:
del self._waiters[job_id]
def NotifyWaiters(self, job_id):
"""Notifies all jobs waiting for a certain job ID.
@attention: Do not call until L{CheckAndRegister} returned a status other
than C{WAITDEP} for C{job_id}, or behaviour is undefined
@type job_id: string
@param job_id: Job ID
"""
assert ht.TString(job_id)
jobs = self._waiters.pop(job_id, None)
self._lock.acquire()
try:
self._RemoveEmptyWaitersUnlocked()
jobs = self._waiters.pop(job_id, None)
finally:
self._lock.release()
if jobs:
# Re-add jobs to workerpool
logging.debug("Re-adding %s jobs which were waiting for job %s",
len(jobs), job_id)
self._enqueue_fn(jobs)
# Remove all jobs without actual waiters
for job_id in [job_id for (job_id, waiters) in self._waiters.items()
if not waiters]:
del self._waiters[job_id]
def _RequireOpenQueue(fn):
"""Decorator for "public" functions.
......
......@@ -1917,6 +1917,9 @@ class TestJobDependencyManager(unittest.TestCase):
return result
def _Enqueue(self, jobs):
self.assertFalse(self.jdm._lock.is_owned(),
msg=("Must not own manager lock while re-adding jobs"
" (potential deadlock)"))
self._queue.append(jobs)
def testNotFinalizedThenCancel(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment