Skip to content

Commit 4494875

Browse files
committed
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 dd8ab32 commit 4494875

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
@@ -101,11 +101,14 @@ def __init__(self, args, ipc_logger_queue: multiprocessing.Queue, log_path: Path
101101
logger.info(f"Agent ID: {self._agent_id}")
102102
logger.info(f"Process ID: {os.getpid()}")
103103

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

107111
self._ipc_logger_queue = ipc_logger_queue
108-
self._manager = multiprocessing.get_context("spawn").Manager()
109112

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

0 commit comments

Comments
 (0)