Skip to content

Commit

Permalink
Agent: Spawn the manager process before acquiring the SystemSingleton
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mssalvatore committed Jan 12, 2023
1 parent 1b88338 commit dcf1e72
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion monkey/infection_monkey/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,14 @@ def __init__(self, args, ipc_logger_queue: multiprocessing.Queue, log_path: Path
logger.info(f"Agent ID: {self._agent_id}")
logger.info(f"Process ID: {os.getpid()}")

# Spawn the manager before the acquiring the singleton in case the file handle gets copied
# over to the manager process
self._manager = multiprocessing.get_context("spawn").Manager()

self._singleton = SystemSingleton()
self._opts = self._get_arguments(args)

self._ipc_logger_queue = ipc_logger_queue
self._manager = multiprocessing.get_context("spawn").Manager()

self._agent_event_forwarder = None
self._agent_event_queue = self._setup_agent_event_queue()
Expand Down

0 comments on commit dcf1e72

Please sign in to comment.