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

Commit

Permalink
Merge pull request #297 from matrix-org/markjh/presence_races
Browse files Browse the repository at this point in the history
Fix some races in the synapse presence handler caused by not yielding…
  • Loading branch information
NegativeMjark committed Oct 12, 2015
2 parents 782f7fb + 9878037 commit 8853014
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions synapse/handlers/presence.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ def set_state(self, target_user, auth_user, state):

# TODO(paul): perform a presence push as part of start/stop poll so
# we don't have to do this all the time
self.changed_presencelike_data(target_user, state)
yield self.changed_presencelike_data(target_user, state)

def bump_presence_active_time(self, user, now=None):
if now is None:
Expand Down Expand Up @@ -422,12 +422,12 @@ def changed_presencelike_data(self, user, state):
@log_function
def started_user_eventstream(self, user):
# TODO(paul): Use "last online" state
self.set_state(user, user, {"presence": PresenceState.ONLINE})
return self.set_state(user, user, {"presence": PresenceState.ONLINE})

@log_function
def stopped_user_eventstream(self, user):
# TODO(paul): Save current state as "last online" state
self.set_state(user, user, {"presence": PresenceState.OFFLINE})
return self.set_state(user, user, {"presence": PresenceState.OFFLINE})

@defer.inlineCallbacks
def user_joined_room(self, user, room_id):
Expand Down Expand Up @@ -1263,6 +1263,11 @@ def __init__(self):
self.state = {"presence": PresenceState.OFFLINE}
self.serial = None

def __repr__(self):
return "UserPresenceCache(state=%r, serial=%r)" % (
self.state, self.serial
)

def update(self, state, serial):
assert("mtime_age" not in state)

Expand Down

0 comments on commit 8853014

Please sign in to comment.