summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorrealtyem <realtyem@gmail.com>2023-02-01 17:42:45 -0600
committerGitHub <noreply@github.com>2023-02-01 23:42:45 +0000
commit58214dbb9b8a85c0dafc65162e9c20ee1885ce4e (patch)
tree2d01f3bc23df0883722b8a690007bf59b37c82e5 /synapse
parentBump hiredis from 2.0.0 to 2.1.1 (#14939) (diff)
downloadsynapse-58214dbb9b8a85c0dafc65162e9c20ee1885ce4e.tar.xz
Allow enabling the asyncio reactor in complement (#14858)
Signed-off-by: Jason Little realtyem@gmail.com
Diffstat (limited to 'synapse')
-rw-r--r--synapse/app/complement_fork_starter.py21
1 files changed, 19 insertions, 2 deletions
diff --git a/synapse/app/complement_fork_starter.py b/synapse/app/complement_fork_starter.py
index 8c0f4a57e7..920538f44d 100644
--- a/synapse/app/complement_fork_starter.py
+++ b/synapse/app/complement_fork_starter.py
@@ -110,6 +110,8 @@ def _worker_entrypoint(
     and then kick off the worker's main() function.
     """
 
+    from synapse.util.stringutils import strtobool
+
     sys.argv = args
 
     # reset the custom signal handlers that we installed, so that the children start
@@ -117,9 +119,24 @@ def _worker_entrypoint(
     for sig, handler in _original_signal_handlers.items():
         signal.signal(sig, handler)
 
-    from twisted.internet.epollreactor import EPollReactor
+    # Install the asyncio reactor if the
+    # SYNAPSE_COMPLEMENT_FORKING_LAUNCHER_ASYNC_IO_REACTOR is set to 1. The
+    # SYNAPSE_ASYNC_IO_REACTOR variable would be used, but then causes
+    # synapse/__init__.py to also try to install an asyncio reactor.
+    if strtobool(
+        os.environ.get("SYNAPSE_COMPLEMENT_FORKING_LAUNCHER_ASYNC_IO_REACTOR", "0")
+    ):
+        import asyncio
+
+        from twisted.internet.asyncioreactor import AsyncioSelectorReactor
+
+        reactor = AsyncioSelectorReactor(asyncio.get_event_loop())
+        proxy_reactor._install_real_reactor(reactor)
+    else:
+        from twisted.internet.epollreactor import EPollReactor
+
+        proxy_reactor._install_real_reactor(EPollReactor())
 
-    proxy_reactor._install_real_reactor(EPollReactor())
     func()