From c0bff448c4f884d99b78c8fcfb640d49a46fd9c8 Mon Sep 17 00:00:00 2001 From: Shreya Date: Mon, 3 Aug 2020 15:56:09 +0530 Subject: [PATCH] Run post-breach phase in separate thread --- monkey/infection_monkey/monkey.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/monkey/infection_monkey/monkey.py b/monkey/infection_monkey/monkey.py index 444bde452..be97332a4 100644 --- a/monkey/infection_monkey/monkey.py +++ b/monkey/infection_monkey/monkey.py @@ -4,6 +4,7 @@ import os import subprocess import sys import time +from threading import Thread import infection_monkey.tunnel as tunnel from common.network.network_utils import get_host_from_network_location @@ -139,8 +140,8 @@ class InfectionMonkey(object): TunnelTelem().send() LOG.debug("Starting the post-breach phase.") - self.collect_system_info_if_configured() - PostBreach().execute_all_configured() + post_breach_phase = Thread(target=self.start_post_breach_phase) + post_breach_phase.start() LOG.debug("Starting the propagation phase.") self.shutdown_by_max_depth_reached() @@ -230,10 +231,17 @@ class InfectionMonkey(object): if monkey_tunnel: monkey_tunnel.stop() monkey_tunnel.join() + + post_breach_phase.join() + except PlannedShutdownException: LOG.info("A planned shutdown of the Monkey occurred. Logging the reason and finishing execution.") LOG.exception("Planned shutdown, reason:") + def start_post_breach_phase(self): + self.collect_system_info_if_configured() + PostBreach().execute_all_configured() + def shutdown_by_max_depth_reached(self): if 0 == WormConfiguration.depth: TraceTelem(MAX_DEPTH_REACHED_MESSAGE).send()