Skip to content

Commit 3c61737

Browse files
committed
fix race condition on direct room
1 parent 7321488 commit 3c61737

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

build/Dockerfile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ COPY workers.patch /tmp/workers.patch
2323
RUN patch $(ls /usr/local/lib/python$PYTHON_PKG_VER/site-packages/synapse/config/workers.py) \
2424
< /tmp/workers.patch \
2525
&& rm /tmp/workers.patch
26+
COPY fix-empty-room-state.patch /tmp/fix-empty-room-state.patch
27+
RUN patch $(ls /usr/local/lib/python$PYTHON_PKG_VER/site-packages/synapse/storage/controllers/state.py) \
28+
< /tmp/fix-empty-room-state.patch \
29+
&& rm /tmp/fix-empty-room-state.patch
2630

2731
# stage 3 : apply e2e_room_keys.patch
2832
FROM pipwheels AS e2e_patch
@@ -41,8 +45,8 @@ COPY --from=workers_patch \
4145
/usr/local/lib/python${PYTHON_PKG_VER}/site-packages/synapse/config/workers.py \
4246
/usr/local/lib/python${PYTHON_PKG_VER}/site-packages/synapse/config/workers.py
4347
COPY --from=workers_patch \
44-
/usr/local/lib/python$PYTHON_PKG_VER/site-packages/synapse/storage/databases/main/event_push_actions.py \
45-
/usr/local/lib/python$PYTHON_PKG_VER/site-packages/synapse/storage/databases/main/event_push_actions.py
48+
/usr/local/lib/python$PYTHON_PKG_VER/site-packages/synapse/storage/controllers/state.py \
49+
/usr/local/lib/python$PYTHON_PKG_VER/site-packages/synapse/storage/controllers/state.py
4650

4751
# stage 5 : base version with e2e_room_keys table optimization
4852
FROM main AS e2e

build/fix-empty-room-state.patch

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
--- a/synapse/storage/controllers/state.py 2026-06-16 02:07:49.851487330 +0300
2+
+++ b/synapse/storage/controllers/state.py 2026-06-16 02:07:13.674945849 +0300
3+
@@ -45,6 +45,7 @@
4+
from synapse.util.caches import intern_string
5+
from synapse.util.caches.descriptors import cached
6+
from synapse.util.cancellation import cancellable
7+
+from synapse.util.duration import Duration
8+
from synapse.util.metrics import Measure
9+
10+
if TYPE_CHECKING:
11+
@@ -458,14 +459,25 @@
12+
)
13+
14+
else:
15+
- # no events in this room - so presumably no state
16+
- state = {}
17+
+ state = await self.get_current_state_ids(
18+
+ room_id,
19+
+ state_filter=state_filter,
20+
+ await_full_state=await_full_state,
21+
+ )
22+
+
23+
+ for _ in range(3):
24+
+ await self.clock.sleep(Duration(seconds=1.5))
25+
+ new_state = await self.get_current_state_ids(
26+
+ room_id,
27+
+ state_filter=state_filter,
28+
+ await_full_state=await_full_state,
29+
+ )
30+
+ if new_state == state:
31+
+ break
32+
+ state = new_state
33+
34+
- # (erikj) This should be rarely hit, but we've had some reports that
35+
- # we get more state down gappy syncs than we should, so let's add
36+
- # some logging.
37+
logger.info(
38+
- "Failed to find any events in room %s at %s",
39+
+ "Failed to find any events in room %s at %s; falling back to current state",
40+
room_id,
41+
stream_position.room_key,
42+
)

0 commit comments

Comments
 (0)