diff options
author | Erik Johnston <erik@matrix.org> | 2023-05-02 17:45:44 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-02 16:45:44 +0000 |
commit | 4de271a7fcde6b46611ba2aa9d45cdc6cc7275ab (patch) | |
tree | e025071d7af46c8d878629f2dfba99aec98e292a /synapse/push | |
parent | Reduce the size of the HTTP connection pool for non-pushers. (#15514) (diff) | |
download | synapse-4de271a7fcde6b46611ba2aa9d45cdc6cc7275ab.tar.xz |
Allow adding random delay to push (#15516)
This is to discourage timing based profiling on the push gateways.
Diffstat (limited to 'synapse/push')
-rw-r--r-- | synapse/push/httppusher.py | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/synapse/push/httppusher.py b/synapse/push/httppusher.py index a01445e374..e628b484a9 100644 --- a/synapse/push/httppusher.py +++ b/synapse/push/httppusher.py @@ -13,6 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. import logging +import random import urllib.parse from typing import TYPE_CHECKING, Dict, List, Optional, Union @@ -114,6 +115,8 @@ class HttpPusher(Pusher): ) self._pusherpool = hs.get_pusherpool() + self.push_jitter_delay_ms = hs.config.push.push_jitter_delay_ms + self.data = pusher_config.data if self.data is None: raise PusherConfigException("'data' key can not be null for HTTP pusher") @@ -327,6 +330,21 @@ class HttpPusher(Pusher): event = await self.store.get_event(push_action.event_id, allow_none=True) if event is None: return True # It's been redacted + + # Check if we should delay sending out the notification by a random + # amount. + # + # Note: we base the delay off of when the event was sent, rather than + # now, to handle the case where we need to send out many notifications + # at once. If we just slept the random amount each loop then the last + # push notification in the set could be delayed by many times the max + # delay. + if self.push_jitter_delay_ms: + delay_ms = random.randint(1, self.push_jitter_delay_ms) + diff_ms = event.origin_server_ts + delay_ms - self.clock.time_msec() + if diff_ms > 0: + await self.clock.sleep(diff_ms / 1000) + rejected = await self.dispatch_push_event(event, tweaks, badge) if rejected is False: return False |