Skip to content

Commit

Permalink
Merge pull request saltstack#50778 from bloomberg/saltnado-fix
Browse files Browse the repository at this point in the history
saltnado: fix timeout handling
  • Loading branch information
Mike Place authored Dec 10, 2018
2 parents c3c2a75 + f803928 commit 71fe054
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions salt/netapi/rest_tornado/saltnado.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,7 @@ def _disbatch_local(self, chunk):
min_wait_time = tornado.gen.sleep(self.application.opts['syndic_wait'])

# To ensure job_not_running and all_return are terminated by each other, communicate using a future
is_timed_out = tornado.gen.sleep(self.application.opts['gather_job_timeout'])
is_finished = Future()

# ping until the job is not running, while doing so, if we see new minions returning
Expand All @@ -1001,18 +1002,18 @@ def more_todo():
# early if gather_job_timeout has been exceeded
chunk_ret = {}
while True:
to_wait = events+[is_finished]
to_wait = events+[is_finished, is_timed_out]
if not min_wait_time.done():
to_wait += [min_wait_time]

def cancel_inflight_futures():
for event in to_wait:
if not event.done():
if not event.done() and event is not is_timed_out:
event.set_result(None)
f = yield Any(to_wait)
try:
# When finished entire routine, cleanup other futures and return result
if f is is_finished:
if f is is_finished or f is is_timed_out:
cancel_inflight_futures()
raise tornado.gen.Return(chunk_ret)
elif f is min_wait_time:
Expand Down Expand Up @@ -1067,7 +1068,7 @@ def job_not_running(self, jid, tgt, tgt_type, minions, is_finished):
if not event.done():
event.set_result(None)

if not minion_running:
if not minion_running or is_finished.done():
raise tornado.gen.Return(True)
else:
ping_pub_data = yield self.saltclients['local'](tgt,
Expand Down

0 comments on commit 71fe054

Please sign in to comment.