Skip to content

Commit b879284

Browse files
erikjohnstonH-Shay
authored andcommitted
Fix bug where typing replication breaks (#17252)
This can happen on restarts of the service, due to old rooms being pruned.
1 parent 09c9e6d commit b879284

3 files changed

Lines changed: 56 additions & 4 deletions

File tree

changelog.d/17252.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix bug where typing updates would not be sent when using workers after a restart.

synapse/handlers/typing.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,9 @@ async def get_all_typing_updates(
477477

478478
rows = []
479479
for room_id in changed_rooms:
480-
serial = self._room_serials[room_id]
481-
if last_id < serial <= current_id:
482-
typing = self._room_typing[room_id]
480+
serial = self._room_serials.get(room_id)
481+
if serial and last_id < serial <= current_id:
482+
typing = self._room_typing.get(room_id, set())
483483
rows.append((serial, [room_id, list(typing)]))
484484
rows.sort()
485485

tests/handlers/test_typing.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
from synapse.api.constants import EduTypes
3333
from synapse.api.errors import AuthError
3434
from synapse.federation.transport.server import TransportLayerServer
35-
from synapse.handlers.typing import TypingWriterHandler
35+
from synapse.handlers.typing import FORGET_TIMEOUT, TypingWriterHandler
3636
from synapse.http.federation.matrix_federation_agent import MatrixFederationAgent
3737
from synapse.server import HomeServer
3838
from synapse.types import JsonDict, Requester, StreamKeyType, UserID, create_requester
@@ -501,3 +501,54 @@ def test_typing_timeout(self) -> None:
501501
}
502502
],
503503
)
504+
505+
def test_prune_typing_replication(self) -> None:
506+
"""Regression test for `get_all_typing_updates` breaking when we prune
507+
old updates
508+
"""
509+
self.room_members = [U_APPLE, U_BANANA]
510+
511+
instance_name = self.hs.get_instance_name()
512+
513+
self.get_success(
514+
self.handler.started_typing(
515+
target_user=U_APPLE,
516+
requester=create_requester(U_APPLE),
517+
room_id=ROOM_ID,
518+
timeout=10000,
519+
)
520+
)
521+
522+
rows, _, _ = self.get_success(
523+
self.handler.get_all_typing_updates(
524+
instance_name=instance_name,
525+
last_id=0,
526+
current_id=self.handler.get_current_token(),
527+
limit=100,
528+
)
529+
)
530+
self.assertEqual(rows, [(1, [ROOM_ID, [U_APPLE.to_string()]])])
531+
532+
self.reactor.advance(20000)
533+
534+
rows, _, _ = self.get_success(
535+
self.handler.get_all_typing_updates(
536+
instance_name=instance_name,
537+
last_id=1,
538+
current_id=self.handler.get_current_token(),
539+
limit=100,
540+
)
541+
)
542+
self.assertEqual(rows, [(2, [ROOM_ID, []])])
543+
544+
self.reactor.advance(FORGET_TIMEOUT)
545+
546+
rows, _, _ = self.get_success(
547+
self.handler.get_all_typing_updates(
548+
instance_name=instance_name,
549+
last_id=1,
550+
current_id=self.handler.get_current_token(),
551+
limit=100,
552+
)
553+
)
554+
self.assertEqual(rows, [])

0 commit comments

Comments
 (0)