From f3a4be870092e28531957702931c5d74b9d1f18f Mon Sep 17 00:00:00 2001
From: Sean Quah <8349537+squahtx@users.noreply.github.com>
Date: Wed, 27 Oct 2021 13:04:56 +0100
Subject: [PATCH] Shut down the DNS threadpool (#11190)

The DNS threadpool must be explicitly stopped, otherwise Synapse will
hang indefinitely when asked to shut down.
---
 changelog.d/11190.bugfix | 1 +
 synapse/app/_base.py     | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 changelog.d/11190.bugfix

diff --git a/changelog.d/11190.bugfix b/changelog.d/11190.bugfix
new file mode 100644
index 0000000000..0d913805ac
--- /dev/null
+++ b/changelog.d/11190.bugfix
@@ -0,0 +1 @@
+Fix a performance regression introduced in 1.44.0 which could cause client requests to time out when making large numbers of outbound requests.
diff --git a/synapse/app/_base.py b/synapse/app/_base.py
index 03627cdcba..f4c3f867a8 100644
--- a/synapse/app/_base.py
+++ b/synapse/app/_base.py
@@ -346,6 +346,7 @@ async def start(hs: "HomeServer"):
     # numbers of DNS requests don't starve out other users of the threadpool.
     resolver_threadpool = ThreadPool(name="gai_resolver")
     resolver_threadpool.start()
+    reactor.addSystemEventTrigger("during", "shutdown", resolver_threadpool.stop)
     reactor.installNameResolver(
         GAIResolver(reactor, getThreadPool=lambda: resolver_threadpool)
     )
-- 
GitLab