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

Copy room serials before handling in get_new_events_as #13392

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions changelog.d/13392.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug in handling of typing events for appservices. Contributed by Nick @ Beeper (@fizzadar).
12 changes: 9 additions & 3 deletions synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,16 +489,22 @@ async def get_new_events_as(
handler = self.get_typing_handler()

events = []
for room_id in handler._room_serials.keys():
if handler._room_serials[room_id] <= from_key:

# Work on a copy of things here as these may change when this coroutine awaits the
# is_interested_in_room call. Shallow copy is safe as no nested data is present.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first I thought this was saying that the call to service.is_interested_in_room might change handler._room_serials, which sounds like an odd thing for an appservice to do. But I think the point is that Synapse itself might change handler._room_serials while the current coroutine is suspended. Do I understand correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's what I meant! Pushed a better comment in 4fe0b2e I think

latest_room_serial = handler._latest_room_serial
room_serials = handler._room_serials.copy()

for room_id, serial in room_serials.items():
if serial <= from_key:
continue

if not await service.is_interested_in_room(room_id, self._main_store):
continue

events.append(self._make_event_for(room_id))

return events, handler._latest_room_serial
return events, latest_room_serial

async def get_new_events(
self,
Expand Down