From 9942880448da6e6e4f44fa530e71cb23d113621f Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Tue, 26 Jul 2022 15:23:26 +0100 Subject: [PATCH 1/3] Copy room serials before handling in `get_new_events_as` --- synapse/handlers/typing.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/synapse/handlers/typing.py b/synapse/handlers/typing.py index d104ea07fedf..a1864b68ecb7 100644 --- a/synapse/handlers/typing.py +++ b/synapse/handlers/typing.py @@ -489,8 +489,14 @@ 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. + 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): @@ -498,7 +504,7 @@ async def get_new_events_as( 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, From 801a11bebb2b67b76451db8af4360d521cbeeae7 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Tue, 26 Jul 2022 15:47:23 +0100 Subject: [PATCH 2/3] Add changelog file --- changelog.d/13392.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog.d/13392.bugfix diff --git a/changelog.d/13392.bugfix b/changelog.d/13392.bugfix new file mode 100644 index 000000000000..7d83c7755073 --- /dev/null +++ b/changelog.d/13392.bugfix @@ -0,0 +1 @@ +Fix bug in handling of typing events for appservices. Contributed by Nick @ Beeper (@fizzadar). From 4fe0b2e31f89b80445b95f3afe451d4abd86374a Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Tue, 26 Jul 2022 18:08:33 +0100 Subject: [PATCH 3/3] Fixup comment --- synapse/handlers/typing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/synapse/handlers/typing.py b/synapse/handlers/typing.py index a1864b68ecb7..27aa0d31266c 100644 --- a/synapse/handlers/typing.py +++ b/synapse/handlers/typing.py @@ -490,8 +490,9 @@ async def get_new_events_as( events = [] - # 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. + # Work on a copy of things here as these may change in the handler while + # waiting for the AS `is_interested_in_room` call to complete. + # Shallow copy is safe as no nested data is present. latest_room_serial = handler._latest_room_serial room_serials = handler._room_serials.copy()