Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug where typing replication breaks #17252

Merged
merged 2 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions changelog.d/17252.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug where typing updates would not be sent when using workers after a restart.
Copy link
Member

Choose a reason for hiding this comment

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

Has this bug been introduced recently, or was it always present?

Copy link
Member Author

Choose a reason for hiding this comment

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

I haven't noticed it before, but I don't think anything has changed recently 🤷

Copy link
Member Author

Choose a reason for hiding this comment

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

(I have a suspicion it's because I upped the stream cache factor)

6 changes: 3 additions & 3 deletions synapse/handlers/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,9 +477,9 @@ async def get_all_typing_updates(

rows = []
for room_id in changed_rooms:
serial = self._room_serials[room_id]
if last_id < serial <= current_id:
typing = self._room_typing[room_id]
serial = self._room_serials.get(room_id)
if serial and last_id < serial <= current_id:
typing = self._room_typing.get(room_id, set())
rows.append((serial, [room_id, list(typing)]))
rows.sort()

Expand Down
53 changes: 52 additions & 1 deletion tests/handlers/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from synapse.api.constants import EduTypes
from synapse.api.errors import AuthError
from synapse.federation.transport.server import TransportLayerServer
from synapse.handlers.typing import TypingWriterHandler
from synapse.handlers.typing import FORGET_TIMEOUT, TypingWriterHandler
from synapse.http.federation.matrix_federation_agent import MatrixFederationAgent
from synapse.server import HomeServer
from synapse.types import JsonDict, Requester, StreamKeyType, UserID, create_requester
Expand Down Expand Up @@ -501,3 +501,54 @@ def test_typing_timeout(self) -> None:
}
],
)

def test_prune_typing_replication(self) -> None:
"""Regression test for `get_all_typing_updates` breaking when we prune
old updates
"""
self.room_members = [U_APPLE, U_BANANA]

instance_name = self.hs.get_instance_name()

self.get_success(
self.handler.started_typing(
target_user=U_APPLE,
requester=create_requester(U_APPLE),
room_id=ROOM_ID,
timeout=10000,
)
)

rows, _, _ = self.get_success(
self.handler.get_all_typing_updates(
instance_name=instance_name,
last_id=0,
current_id=self.handler.get_current_token(),
limit=100,
)
)
self.assertEqual(rows, [(1, [ROOM_ID, [U_APPLE.to_string()]])])

self.reactor.advance(20000)

rows, _, _ = self.get_success(
self.handler.get_all_typing_updates(
instance_name=instance_name,
last_id=1,
current_id=self.handler.get_current_token(),
limit=100,
)
)
self.assertEqual(rows, [(2, [ROOM_ID, []])])

self.reactor.advance(FORGET_TIMEOUT)

rows, _, _ = self.get_success(
self.handler.get_all_typing_updates(
instance_name=instance_name,
last_id=1,
current_id=self.handler.get_current_token(),
limit=100,
)
)
self.assertEqual(rows, [])
Loading