summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorErik Johnston <erik@matrix.org>2015-03-06 10:28:19 +0000
committerErik Johnston <erik@matrix.org>2015-03-06 10:28:19 +0000
commite780492ecfd4197b38a0c5dbfa256ff6cd064779 (patch)
treecf15d02559af040e927ac4ace9136fcaf220d530 /synapse
parentLog error message when we fail to fetch remote server keys (diff)
parentAdd some randomness to the user specified timeout on event streams to mitigat... (diff)
downloadsynapse-e780492ecfd4197b38a0c5dbfa256ff6cd064779.tar.xz
Merge pull request #102 from matrix-org/randomize_stream_timeout
Add some randomness to the user specified timeout on event streams to mi...
Diffstat (limited to 'synapse')
-rw-r--r--synapse/handlers/events.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/synapse/handlers/events.py b/synapse/handlers/events.py
index 8d5f5c8499..d3297b7292 100644
--- a/synapse/handlers/events.py
+++ b/synapse/handlers/events.py
@@ -23,6 +23,7 @@ from synapse.events.utils import serialize_event
 from ._base import BaseHandler
 
 import logging
+import random
 
 
 logger = logging.getLogger(__name__)
@@ -72,6 +73,14 @@ class EventStreamHandler(BaseHandler):
             rm_handler = self.hs.get_handlers().room_member_handler
             room_ids = yield rm_handler.get_rooms_for_user(auth_user)
 
+            if timeout:
+                # If they've set a timeout set a minimum limit.
+                timeout = max(timeout, 500)
+
+                # Add some randomness to this value to try and mitigate against
+                # thundering herds on restart.
+                timeout = random.randint(int(timeout*0.9), int(timeout*1.1))
+
             with PreserveLoggingContext():
                 events, tokens = yield self.notifier.get_events_for(
                     auth_user, room_ids, pagin_config, timeout