Skip to content

Commit

Permalink
Agent: Use spawn context for LDAP server process
Browse files Browse the repository at this point in the history
Forked processes will inherit all resources from the parent process.
This includes the socket we use for ensuring only a single agent is
running at any given time. Additionaly, threads will also be inherited
by the forked process, which could cause problems.

Using a spawn context should fix our singleton issue, and give the
process a cleaner environment in which to run.

Issue #2820
  • Loading branch information
cakekoa committed Jan 13, 2023
1 parent 4bacb7b commit eb3b77a
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(
:param storage_dir: A directory where the LDAP server can safely store files it needs during
runtime.
"""
self._reactor_startup_completed = multiprocessing.Event()
self._reactor_startup_completed = multiprocessing.get_context("spawn").Event()
self._ldap_server_port = ldap_server_port
self._http_server_ip = http_server_ip
self._http_server_port = http_server_port
Expand All @@ -114,7 +114,7 @@ def run(self):
# has been stopped. To work around this, the reactor is configured and run in a separate
# process. This allows us to run multiple LDAP servers sequentially or simultaneously and
# stop each one when we're done with it.
self._server_process = multiprocessing.Process(
self._server_process = multiprocessing.get_context("spawn").Process(
name=f"{threading.current_thread()}-LDAPServer-{insecure_generate_random_string(n=8)}",
target=self._run_twisted_reactor,
daemon=True,
Expand Down

0 comments on commit eb3b77a

Please sign in to comment.