Skip to content

Commit b0d0d1b

Browse files
mssalvatorecakekoa
authored andcommitted
Agent: Spawn the manager process before acquiring the SystemSingleton
The SystemSingleton uses an abstract unix socket as a "lock" to ensure only one agent at a time runs on a given machine. It seems that if a manager process is spawned after this unix socket is created, the manager process inherits this file handle, which leads to the socket never being properly closed. Spawning the manager before the socket is opened is a quick solution to this problem. A better solution (see #2817) is to use a different method than a unix socket to achieve this goal, but, baby steps for now.
1 parent 88d353d commit b0d0d1b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

monkey/infection_monkey/monkey.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,14 @@ def __init__(self, args, ipc_logger_queue: multiprocessing.Queue, log_path: Path
102102
logger.info(f"Agent ID: {self._agent_id}")
103103
logger.info(f"Process ID: {os.getpid()}")
104104

105+
# Spawn the manager before the acquiring the singleton in case the file handle gets copied
106+
# over to the manager process
107+
self._manager = multiprocessing.get_context("spawn").Manager()
108+
105109
self._singleton = SystemSingleton()
106110
self._opts = self._get_arguments(args)
107111

108112
self._ipc_logger_queue = ipc_logger_queue
109-
self._manager = multiprocessing.get_context("spawn").Manager()
110113

111114
self._agent_event_forwarder = None
112115
self._agent_event_queue = self._setup_agent_event_queue()

0 commit comments

Comments
 (0)