Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Prevent memory leak from reoccurring when presence is disabled. #12656

Merged
merged 5 commits into from
May 6, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,27 +659,28 @@ def __init__(self, hs: "HomeServer"):
)

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:
DMRobertson marked this conversation as resolved.
Show resolved Hide resolved
for state in self.user_to_current_state.values():
self.wheel_timer.insert(
now=now,
obj=state.user_id,
then=state.last_federation_update_ts + FEDERATION_PING_INTERVAL,
now=now, obj=state.user_id, then=state.last_active_ts + IDLE_TIMER
)
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
Expand Down Expand Up @@ -804,6 +805,13 @@ async def _update_states(
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"):
Expand Down Expand Up @@ -1229,6 +1237,10 @@ async def set_state(
):
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)
Expand Down