commit 15bfb0312030a79c1985564dcbf7ee18101388b4 Author: Leonid Evdokimov leon@darkk.net.ru Date: Mon Oct 10 23:06:50 2016 +0300
Fix #612 deadlock confirmed by TestScheduler.test_thundering_herd
The trivial fix makes sense as current SchedulerService ticks every 30 seconds and imprecise scheduling is acceptable. --- ooni/agent/scheduler.py | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git a/ooni/agent/scheduler.py b/ooni/agent/scheduler.py index f6b52b7..969602a 100644 --- a/ooni/agent/scheduler.py +++ b/ooni/agent/scheduler.py @@ -61,6 +61,11 @@ class DidNotRun(Exception):
class ScheduledTask(object): + """ + Two ScheduledTask instances with same identifier are not permited to run + concurrently. There should be no ScheduledTask queue waiting for the lock + as SchedulerService ticks quite often. + """ _time_format = "%Y-%m-%dT%H:%M:%SZ" schedule = None identifier = None @@ -117,6 +122,9 @@ class ScheduledTask(object):
@defer.inlineCallbacks def run(self): + if self._last_run_lock.locked: + # do not allow the queue to grow forever + raise DidNotRun yield self._last_run_lock.acquire() if not self.should_run: self._last_run_lock.release()
tor-commits@lists.torproject.org