diff options
author | Andrew Morgan <1342360+anoadragon453@users.noreply.github.com> | 2019-01-24 15:24:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-24 15:24:35 +0000 |
commit | 50c396a7eefb31c2ccfe272a6e796ef9b0a161ca (patch) | |
tree | 00835317b059d534c3e19aa22cf27cc4f2957f89 | |
parent | Merge pull request #4464 from matrix-org/rav/fix_srv_lookup (diff) | |
parent | Change default timeout value from 0 to None (diff) | |
download | synapse-50c396a7eefb31c2ccfe272a6e796ef9b0a161ca.tar.xz |
Merge pull request #4461 from matrix-org/anoa/room_dir_quick_fix
Add a 60s timeout to filtered room directory queries
-rw-r--r-- | changelog.d/4461.bugfix | 1 | ||||
-rw-r--r-- | synapse/handlers/room_list.py | 14 |
2 files changed, 13 insertions, 2 deletions
diff --git a/changelog.d/4461.bugfix b/changelog.d/4461.bugfix new file mode 100644 index 0000000000..92062a2bfb --- /dev/null +++ b/changelog.d/4461.bugfix @@ -0,0 +1 @@ +Add a timeout to filtered room directory queries. \ No newline at end of file diff --git a/synapse/handlers/room_list.py b/synapse/handlers/room_list.py index dc88620885..13e212d669 100644 --- a/synapse/handlers/room_list.py +++ b/synapse/handlers/room_list.py @@ -73,8 +73,14 @@ class RoomListHandler(BaseHandler): # We explicitly don't bother caching searches or requests for # appservice specific lists. logger.info("Bypassing cache as search request.") + + # XXX: Quick hack to stop room directory queries taking too long. + # Timeout request after 60s. Probably want a more fundamental + # solution at some point + timeout = self.clock.time() + 60 return self._get_public_room_list( - limit, since_token, search_filter, network_tuple=network_tuple, + limit, since_token, search_filter, + network_tuple=network_tuple, timeout=timeout, ) key = (limit, since_token, network_tuple) @@ -87,7 +93,8 @@ class RoomListHandler(BaseHandler): @defer.inlineCallbacks def _get_public_room_list(self, limit=None, since_token=None, search_filter=None, - network_tuple=EMPTY_THIRD_PARTY_ID,): + network_tuple=EMPTY_THIRD_PARTY_ID, + timeout=None,): if since_token and since_token != "END": since_token = RoomListNextBatch.from_token(since_token) else: @@ -202,6 +209,9 @@ class RoomListHandler(BaseHandler): chunk = [] for i in range(0, len(rooms_to_scan), step): + if timeout and self.clock.time() > timeout: + raise Exception("Timed out searching room directory") + batch = rooms_to_scan[i:i + step] logger.info("Processing %i rooms for result", len(batch)) yield concurrently_execute( |