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

Fix a race between started/stopped stream #444

Merged
merged 1 commit into from
Dec 14, 2015
Merged
Changes from all commits
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
11 changes: 8 additions & 3 deletions synapse/handlers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ def started_stream(self, user):
A deferred that completes once their presence has been updated.
"""
if user not in self._streams_per_user:
self._streams_per_user[user] = 0
# Make sure we set the streams per user to 1 here rather than
# setting it to zero and incrementing the value below.
# Otherwise this may race with stopped_stream causing the
# user to be erased from the map before we have a chance
# to increment it.
self._streams_per_user[user] = 1
if user in self._stop_timer_per_user:
try:
self.clock.cancel_call_later(
Expand All @@ -79,8 +84,8 @@ def started_stream(self, user):
logger.exception("Failed to cancel event timer")
else:
yield started_user_eventstream(self.distributor, user)

self._streams_per_user[user] += 1
else:
self._streams_per_user[user] += 1

def stopped_stream(self, user):
"""If there are no streams for a user this starts a timer that will
Expand Down