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

Commit

Permalink
Fix race condition in room stats. (#6029)
Browse files Browse the repository at this point in the history
  • Loading branch information
anoadragon453 committed Feb 25, 2020
2 parents 74912d4 + 70c5282 commit c0648d6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions changelog.d/6029.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix room and user stats tracking.
14 changes: 10 additions & 4 deletions synapse/handlers/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ def _unsafe_process(self):
# Loop round handling deltas until we're up to date

while True:
# Be sure to read the max stream_ordering *before* checking if there are any outstanding
# deltas, since there is otherwise a chance that we could miss updates which arrive
# after we check the deltas.
room_max_stream_ordering = yield self.store.get_room_max_stream_ordering()
if self.pos == room_max_stream_ordering:
break

deltas = yield self.store.get_current_state_deltas(self.pos)

if deltas:
Expand All @@ -94,7 +101,7 @@ def _unsafe_process(self):
else:
room_deltas = {}
user_deltas = {}
max_pos = yield self.store.get_room_max_stream_ordering()
max_pos = room_max_stream_ordering

# Then count deltas for total_events and total_event_bytes.
room_count, user_count = yield self.store.get_changes_room_total_events_and_bytes(
Expand All @@ -117,10 +124,9 @@ def _unsafe_process(self):
stream_id=max_pos,
)

event_processing_positions.labels("stats").set(max_pos)
logger.debug("Handled room stats to %s -> %s", self.pos, max_pos)

if self.pos == max_pos:
break
event_processing_positions.labels("stats").set(max_pos)

self.pos = max_pos

Expand Down

0 comments on commit c0648d6

Please sign in to comment.