mirror of
https://git.anonymousland.org/anonymousland/synapse.git
synced 2025-08-08 18:02:23 -04:00
Prevent memory leak from reoccurring when presence is disabled. (#12656)
This commit is contained in:
parent
2607b3e181
commit
4337d33a73
3 changed files with 56 additions and 30 deletions
|
@ -659,27 +659,28 @@ class PresenceHandler(BasePresenceHandler):
|
|||
)
|
||||
|
||||
now = self.clock.time_msec()
|
||||
for state in self.user_to_current_state.values():
|
||||
self.wheel_timer.insert(
|
||||
now=now, obj=state.user_id, then=state.last_active_ts + IDLE_TIMER
|
||||
)
|
||||
self.wheel_timer.insert(
|
||||
now=now,
|
||||
obj=state.user_id,
|
||||
then=state.last_user_sync_ts + SYNC_ONLINE_TIMEOUT,
|
||||
)
|
||||
if self.is_mine_id(state.user_id):
|
||||
if self._presence_enabled:
|
||||
for state in self.user_to_current_state.values():
|
||||
self.wheel_timer.insert(
|
||||
now=now, obj=state.user_id, then=state.last_active_ts + IDLE_TIMER
|
||||
)
|
||||
self.wheel_timer.insert(
|
||||
now=now,
|
||||
obj=state.user_id,
|
||||
then=state.last_federation_update_ts + FEDERATION_PING_INTERVAL,
|
||||
)
|
||||
else:
|
||||
self.wheel_timer.insert(
|
||||
now=now,
|
||||
obj=state.user_id,
|
||||
then=state.last_federation_update_ts + FEDERATION_TIMEOUT,
|
||||
then=state.last_user_sync_ts + SYNC_ONLINE_TIMEOUT,
|
||||
)
|
||||
if self.is_mine_id(state.user_id):
|
||||
self.wheel_timer.insert(
|
||||
now=now,
|
||||
obj=state.user_id,
|
||||
then=state.last_federation_update_ts + FEDERATION_PING_INTERVAL,
|
||||
)
|
||||
else:
|
||||
self.wheel_timer.insert(
|
||||
now=now,
|
||||
obj=state.user_id,
|
||||
then=state.last_federation_update_ts + FEDERATION_TIMEOUT,
|
||||
)
|
||||
|
||||
# Set of users who have presence in the `user_to_current_state` that
|
||||
# have not yet been persisted
|
||||
|
@ -804,6 +805,13 @@ class PresenceHandler(BasePresenceHandler):
|
|||
This is currently used to bump the max presence stream ID without changing any
|
||||
user's presence (see PresenceHandler.add_users_to_send_full_presence_to).
|
||||
"""
|
||||
if not self._presence_enabled:
|
||||
# We shouldn't get here if presence is disabled, but we check anyway
|
||||
# to ensure that we don't a) send out presence federation and b)
|
||||
# don't add things to the wheel timer that will never be handled.
|
||||
logger.warning("Tried to update presence states when presence is disabled")
|
||||
return
|
||||
|
||||
now = self.clock.time_msec()
|
||||
|
||||
with Measure(self.clock, "presence_update_states"):
|
||||
|
@ -1229,6 +1237,10 @@ class PresenceHandler(BasePresenceHandler):
|
|||
):
|
||||
raise SynapseError(400, "Invalid presence state")
|
||||
|
||||
# If presence is disabled, no-op
|
||||
if not self.hs.config.server.use_presence:
|
||||
return
|
||||
|
||||
user_id = target_user.to_string()
|
||||
|
||||
prev_state = await self.current_state_for_user(user_id)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue