Skip to content

Commit 3f0f03d

Browse files
authored
Revert "Send a SSS response immediately if the config has changed and there are new results to sync (#19714)" (#19784)
Reverts: #19714 Opens: #19783 Closes: element-hq/backend-internal#242 Related: #18880 (the performance problem that is aggravated by #19714) This reverts commit 2691d0b. --------- Signed-off-by: Olivier 'reivilibre <oliverw@matrix.org>
1 parent 9ce68a6 commit 3f0f03d

4 files changed

Lines changed: 29 additions & 155 deletions

File tree

changelog.d/19784.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Revert 'Have [MSC4186: Simplified Sliding Sync](https://github.com/matrix-org/matrix-spec-proposals/pull/4186) return a new response immediately if a room subscription has changed and produced a new response. ([\#19714](https://github.com/element-hq/synapse/issues/19714))' due to performance problems.

synapse/handlers/sliding_sync/__init__.py

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -184,38 +184,34 @@ async def wait_for_sync_for_user(
184184
timeout_ms -= after_wait_ts - before_wait_ts
185185
timeout_ms = max(timeout_ms, 0)
186186

187-
# Compute a response immediately. We always need to do this before
188-
# waiting for new data (unlike in /v3/sync), as the request config might
189-
# have changed (e.g. new room subscriptions, etc).
190-
now_token = self.event_sources.get_current_token()
191-
result = await self.current_sync_for_user(
192-
sync_config,
193-
from_token=from_token,
194-
to_token=now_token,
195-
)
196-
197-
# Return immediately if we have a result, the timeout is 0, or this is
198-
# an initial sync.
199-
if result or timeout_ms == 0 or from_token is None:
200-
return result, did_wait
201-
202-
# Otherwise, we wait for something to happen and report it to the user.
203-
async def current_sync_callback(
204-
before_token: StreamToken, after_token: StreamToken
205-
) -> SlidingSyncResult:
206-
return await self.current_sync_for_user(
187+
# We're going to respond immediately if the timeout is 0 or if this is an
188+
# initial sync (without a `from_token`) so we can avoid calling
189+
# `notifier.wait_for_events()`.
190+
if timeout_ms == 0 or from_token is None:
191+
now_token = self.event_sources.get_current_token()
192+
result = await self.current_sync_for_user(
207193
sync_config,
208194
from_token=from_token,
209-
to_token=after_token,
195+
to_token=now_token,
210196
)
197+
else:
198+
# Otherwise, we wait for something to happen and report it to the user.
199+
async def current_sync_callback(
200+
before_token: StreamToken, after_token: StreamToken
201+
) -> SlidingSyncResult:
202+
return await self.current_sync_for_user(
203+
sync_config,
204+
from_token=from_token,
205+
to_token=after_token,
206+
)
211207

212-
result = await self.notifier.wait_for_events(
213-
sync_config.user.to_string(),
214-
timeout_ms,
215-
current_sync_callback,
216-
from_token=now_token,
217-
)
218-
did_wait = True
208+
result = await self.notifier.wait_for_events(
209+
sync_config.user.to_string(),
210+
timeout_ms,
211+
current_sync_callback,
212+
from_token=from_token.stream_token,
213+
)
214+
did_wait = True
219215

220216
return result, did_wait
221217

synapse/handlers/sliding_sync/room_lists.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -852,15 +852,11 @@ async def _filter_relevant_rooms_to_send(
852852
previous_connection_state.room_configs.get(room_id)
853853
)
854854
if prev_room_sync_config is not None:
855-
# Always include rooms whose effective config has
856-
# expanded. This covers timeline-limit increases and
857-
# required-state additions introduced by room
858-
# subscriptions overriding list-derived params.
855+
# Always include rooms whose timeline limit has increased.
856+
# (see the "XXX: Odd behavior" described below)
859857
if (
860-
prev_room_sync_config.combine_room_sync_config(
861-
room_config
862-
)
863-
!= prev_room_sync_config
858+
prev_room_sync_config.timeline_limit
859+
< room_config.timeline_limit
864860
):
865861
rooms_should_send.add(room_id)
866862
continue

tests/rest/client/sliding_sync/test_room_subscriptions.py

Lines changed: 0 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
from synapse.api.constants import EventTypes, HistoryVisibility
2323
from synapse.rest.client import login, room, sync
2424
from synapse.server import HomeServer
25-
from synapse.types import JsonDict
2625
from synapse.util.clock import Clock
2726

2827
from tests.rest.client.sliding_sync.test_sliding_sync import SlidingSyncBase
@@ -127,124 +126,6 @@ def test_room_subscriptions_with_join_membership(self) -> None:
127126
response_body["rooms"][room_id1],
128127
)
129128

130-
def test_room_subscription_required_state_expansion_returns_immediately(
131-
self,
132-
) -> None:
133-
"""
134-
Test that adding a room subscription with stronger params than the list causes an
135-
incremental long-poll to return immediately, even without new stream activity.
136-
"""
137-
user1_id = self.register_user("user1", "pass")
138-
user1_tok = self.login(user1_id, "pass")
139-
140-
room_id1 = self.helper.create_room_as(user1_id, tok=user1_tok)
141-
142-
sync_body: JsonDict = {
143-
"lists": {
144-
"foo-list": {
145-
"ranges": [[0, 0]],
146-
"required_state": [],
147-
"timeline_limit": 0,
148-
}
149-
},
150-
"conn_id": "conn_id",
151-
}
152-
_, from_token = self.do_sync(sync_body, tok=user1_tok)
153-
154-
sync_body["room_subscriptions"] = {
155-
room_id1: {
156-
"required_state": [
157-
[EventTypes.Create, ""],
158-
],
159-
"timeline_limit": 0,
160-
}
161-
}
162-
163-
channel = self.make_request(
164-
"POST",
165-
self.sync_endpoint + f"?timeout=10000&pos={from_token}",
166-
content=sync_body,
167-
access_token=user1_tok,
168-
await_result=False,
169-
)
170-
channel.await_result(timeout_ms=3000)
171-
self.assertEqual(channel.code, 200, channel.json_body)
172-
173-
state_map = self.get_success(
174-
self.storage_controllers.state.get_current_state(room_id1)
175-
)
176-
177-
room_response = channel.json_body["rooms"][room_id1]
178-
self.assertNotIn("initial", room_response)
179-
self._assertRequiredStateIncludes(
180-
room_response["required_state"],
181-
{
182-
state_map[(EventTypes.Create, "")],
183-
},
184-
exact=True,
185-
)
186-
187-
def test_room_subscription_required_state_change_returns_immediately(self) -> None:
188-
"""
189-
Test that expanding an existing room subscription's required state causes an
190-
incremental long-poll to return immediately, even without new stream activity.
191-
"""
192-
user1_id = self.register_user("user1", "pass")
193-
user1_tok = self.login(user1_id, "pass")
194-
195-
room_id1 = self.helper.create_room_as(
196-
user1_id, tok=user1_tok, extra_content={"name": "Foo"}
197-
)
198-
199-
sync_body: JsonDict = {
200-
"room_subscriptions": {
201-
room_id1: {
202-
"required_state": [
203-
[EventTypes.Create, ""],
204-
],
205-
"timeline_limit": 0,
206-
}
207-
},
208-
"conn_id": "conn_id",
209-
}
210-
response_body, from_token = self.do_sync(sync_body, tok=user1_tok)
211-
212-
state_map = self.get_success(
213-
self.storage_controllers.state.get_current_state(room_id1)
214-
)
215-
self._assertRequiredStateIncludes(
216-
response_body["rooms"][room_id1]["required_state"],
217-
{
218-
state_map[(EventTypes.Create, "")],
219-
},
220-
exact=True,
221-
)
222-
223-
sync_body["room_subscriptions"][room_id1]["required_state"] = [
224-
[EventTypes.Create, ""],
225-
[EventTypes.Name, ""],
226-
]
227-
228-
channel = self.make_request(
229-
"POST",
230-
self.sync_endpoint + f"?timeout=10000&pos={from_token}",
231-
content=sync_body,
232-
access_token=user1_tok,
233-
await_result=False,
234-
)
235-
channel.await_result(timeout_ms=3000)
236-
self.assertEqual(channel.code, 200, channel.json_body)
237-
238-
room_response = channel.json_body["rooms"][room_id1]
239-
self.assertNotIn("initial", room_response)
240-
self._assertRequiredStateIncludes(
241-
room_response["required_state"],
242-
{
243-
state_map[(EventTypes.Name, "")],
244-
},
245-
exact=True,
246-
)
247-
248129
def test_room_subscriptions_with_leave_membership(self) -> None:
249130
"""
250131
Test `room_subscriptions` with a leave room should give us timeline and state

0 commit comments

Comments
 (0)