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

Commit ce91ef5

Browse files
author
David Robertson
committed
Don't drop user dir deltas when server leaves room
Fix a long-standing bug where a batch of user directory changes would be silently dropped if the server left a room early in the batch.
1 parent 0491be6 commit ce91ef5

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

synapse/handlers/user_directory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ async def _handle_deltas(self, deltas: List[Dict[str, Any]]) -> None:
220220

221221
for user_id in user_ids:
222222
await self._handle_remove_user(room_id, user_id)
223-
return
223+
continue
224224
else:
225225
logger.debug("Server is still in room: %r", room_id)
226226

tests/handlers/test_user_directory.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,45 @@ def test_reactivation_makes_regular_user_searchable(self) -> None:
363363
self.assertEqual(len(s["results"]), 1)
364364
self.assertEqual(s["results"][0]["user_id"], user)
365365

366+
def test_process_join_after_server_leaves_room(self) -> None:
367+
alice = self.register_user("alice", "pass")
368+
alice_token = self.login(alice, "pass")
369+
bob = self.register_user("bob", "pass")
370+
bob_token = self.login(bob, "pass")
371+
372+
# Alice makes two rooms. Bob joins one of them.
373+
room1 = self.helper.create_room_as(alice, tok=alice_token)
374+
room2 = self.helper.create_room_as(alice, tok=alice_token)
375+
print("room1=", room1)
376+
print("room2=", room2)
377+
self.helper.join(room1, bob, tok=bob_token)
378+
379+
# The user sharing tables should have been updated.
380+
public1 = self.get_success(self.user_dir_helper.get_users_in_public_rooms())
381+
self.assertEqual(set(public1), {(alice, room1), (alice, room2), (bob, room1)})
382+
383+
# Alice leaves room1. The user sharing tables should be updated.
384+
self.helper.leave(room1, alice, tok=alice_token)
385+
public2 = self.get_success(self.user_dir_helper.get_users_in_public_rooms())
386+
self.assertEqual(set(public2), {(alice, room2), (bob, room1)})
387+
388+
# Pause the processing of new events.
389+
dir_handler = self.hs.get_user_directory_handler()
390+
dir_handler.update_user_directory = False
391+
392+
# Bob leaves one room and joins the other.
393+
self.helper.leave(room1, bob, tok=bob_token)
394+
self.helper.join(room2, bob, tok=bob_token)
395+
396+
# Process the leave and join in one go.
397+
dir_handler.update_user_directory = True
398+
dir_handler.notify_new_event()
399+
self.wait_for_background_updates()
400+
401+
# The user sharing tables should have been updated.
402+
public3 = self.get_success(self.user_dir_helper.get_users_in_public_rooms())
403+
self.assertEqual(set(public3), {(alice, room2), (bob, room2)})
404+
366405
def test_private_room(self) -> None:
367406
"""
368407
A user can be searched for only by people that are either in a public

0 commit comments

Comments
 (0)