-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Add a 60s timeout to filtered room directory queries #4461
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #4461 +/- ##
===========================================
+ Coverage 74.81% 74.82% +0.01%
===========================================
Files 336 336
Lines 33998 34003 +5
Branches 5527 5529 +2
===========================================
+ Hits 25434 25444 +10
+ Misses 7003 6994 -9
- Partials 1561 1565 +4 |
synapse/handlers/room_list.py
Outdated
# 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 = datetime.now() + timedelta(seconds=60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the record, I'm not generally a fan of datetime objects when a simple "seconds since the epoch" will do and be much more explicit. They have a whole bunch of arithmetic and timezone logic which is pretty redundant here. (In this case, self.clock.time() + 60
will do what you want).
I'm happy if you want to leave this though, given it's a quick hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(as a question to ponder: what will this do when the clocks change? I think it will do the right thing, but tbh who knows. It's a question you just don't need to worry about with "seconds since the epoch".)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed it to just use epoch seconds, thanks for the heads up :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better!
synapse/handlers/room_list.py
Outdated
@@ -87,7 +93,8 @@ def get_local_public_room_list(self, limit=None, since_token=None, | |||
@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=0,): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
None
is probably better as a magic value than 0, fwiw
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probs
Protects against longstanding queries piling up in the background and blocking new ones.