Skip to content

Commit 832fcd7

Browse files
committed
fixes #2595
retry multiple times on `intelmqctl stop` to check if bots really stopped, since the bots might take longer to stop. Using retry in constrast to increasing the sleep_time keeps the delay short in case the bots did already stop.
1 parent ec37d0c commit 832fcd7

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

intelmq/bin/intelmqctl.py

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -563,12 +563,36 @@ def botnet_stop(self, group=None):
563563
for bot_id in bots:
564564
self.bot_stop(bot_id, getstatus=False)
565565

566-
retval = 0
567-
time.sleep(0.75)
568-
for bot_id in bots:
569-
botnet_status[bot_id] = self.bot_status(bot_id)[1]
570-
if botnet_status[bot_id] not in ['stopped', 'disabled']:
571-
retval = 1
566+
# shallow copy of the list suffices
567+
# only aliasing the list to ease reading the following
568+
stopped_but_still_running_bots = bots
569+
570+
# parameters:
571+
# - sleep 0.75 s with an increment of 0.1
572+
# - at most 5 tries
573+
# => sleep-ing at most 4.75 seconds
574+
sleep_time = 0.75 # in seconds
575+
for _ in range(5):
576+
# give the bots some time to terminate
577+
time.sleep(sleep_time)
578+
# update the botnet_status
579+
for bot_id in stopped_but_still_running_bots:
580+
botnet_status[bot_id] = self.bot_status(bot_id)[1]
581+
if botnet_status[bot_id] in ['stopped', 'disabled']:
582+
stopped_but_still_running_bots.remove(bot_id)
583+
584+
# check if all bots are stopped -> no need to wait further
585+
if len(stopped_but_still_running_bots) == 0:
586+
break
587+
# the longer the bots need to terminate the longer we wait to check
588+
# again to avoid long-term load on the system
589+
# but stop at 5 seconds to avoid waiting too long until rechecking
590+
# the status
591+
sleep_time = min(5, sleep_time+0.1)
592+
593+
retval = 1
594+
if len(stopped_but_still_running_bots) == 0:
595+
retval = 0
572596

573597
self.log_botnet_message('stopped', group)
574598
return retval, botnet_status

0 commit comments

Comments
 (0)