Skip to content

Commit

Permalink
Check startup delayed state events for same state
Browse files Browse the repository at this point in the history
If on startup there are multiple delayed state events to be sent, do not
send multiple events that target the same state key for a room.
  • Loading branch information
AndrewFerr committed Aug 2, 2024
1 parent 6466bd1 commit f61c96f
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions synapse/handlers/delayed_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
Dict,
List,
Optional,
Set,
Tuple,
)

import attr
Expand Down Expand Up @@ -100,11 +102,35 @@ async def _schedule_db_events() -> None:
events, remaining_timeout_delays = await self.store.process_all_delays(
self._get_current_ts()
)
for args in events:
sent_state: Set[Tuple[RoomID, EventType, StateKey]] = set()
for (
user_localpart,
room_id,
event_type,
state_key,
timestamp,
content,
) in events:
if state_key is not None:
state_info = (room_id, event_type, state_key)
if state_info in sent_state:
continue
else:
state_info = None
try:
await self._send_event(*args)
await self._send_event(
user_localpart,
room_id,
event_type,
state_key,
timestamp,
content,
)
if state_info is not None:
sent_state.add(state_info)
except Exception:
logger.exception("Failed to send delayed event on startup")
sent_state.clear()

for delay_id, user_localpart, relative_delay in remaining_timeout_delays:
self._schedule(delay_id, user_localpart, relative_delay)
Expand Down

0 comments on commit f61c96f

Please sign in to comment.