|
53 | 53 | from synapse.events.utils import SerializeEventConfig, maybe_upsert_event_field |
54 | 54 | from synapse.events.validator import EventValidator |
55 | 55 | from synapse.handlers.directory import DirectoryHandler |
| 56 | +from synapse.handlers.worker_lock import DELETE_ROOM_LOCK_NAME |
56 | 57 | from synapse.logging import opentracing |
57 | 58 | from synapse.logging.context import make_deferred_yieldable, run_in_background |
58 | 59 | from synapse.metrics.background_process_metrics import run_as_background_process |
@@ -485,6 +486,7 @@ def __init__(self, hs: "HomeServer"): |
485 | 486 | self._events_shard_config = self.config.worker.events_shard_config |
486 | 487 | self._instance_name = hs.get_instance_name() |
487 | 488 | self._notifier = hs.get_notifier() |
| 489 | + self._worker_lock_handler = hs.get_worker_locks_handler() |
488 | 490 |
|
489 | 491 | self.room_prejoin_state_types = self.hs.config.api.room_prejoin_state |
490 | 492 |
|
@@ -1010,6 +1012,37 @@ async def create_and_send_nonmember_event( |
1010 | 1012 | event.internal_metadata.stream_ordering, |
1011 | 1013 | ) |
1012 | 1014 |
|
| 1015 | + async with self._worker_lock_handler.acquire_read_write_lock( |
| 1016 | + DELETE_ROOM_LOCK_NAME, room_id, write=False |
| 1017 | + ): |
| 1018 | + return await self._create_and_send_nonmember_event( |
| 1019 | + requester=requester, |
| 1020 | + event_dict=event_dict, |
| 1021 | + allow_no_prev_events=allow_no_prev_events, |
| 1022 | + prev_event_ids=prev_event_ids, |
| 1023 | + state_event_ids=state_event_ids, |
| 1024 | + ratelimit=ratelimit, |
| 1025 | + txn_id=txn_id, |
| 1026 | + ignore_shadow_ban=ignore_shadow_ban, |
| 1027 | + outlier=outlier, |
| 1028 | + depth=depth, |
| 1029 | + ) |
| 1030 | + |
| 1031 | + async def _create_and_send_nonmember_event( |
| 1032 | + self, |
| 1033 | + requester: Requester, |
| 1034 | + event_dict: dict, |
| 1035 | + allow_no_prev_events: bool = False, |
| 1036 | + prev_event_ids: Optional[List[str]] = None, |
| 1037 | + state_event_ids: Optional[List[str]] = None, |
| 1038 | + ratelimit: bool = True, |
| 1039 | + txn_id: Optional[str] = None, |
| 1040 | + ignore_shadow_ban: bool = False, |
| 1041 | + outlier: bool = False, |
| 1042 | + depth: Optional[int] = None, |
| 1043 | + ) -> Tuple[EventBase, int]: |
| 1044 | + room_id = event_dict["room_id"] |
| 1045 | + |
1013 | 1046 | # If we don't have any prev event IDs specified then we need to |
1014 | 1047 | # check that the host is in the room (as otherwise populating the |
1015 | 1048 | # prev events will fail), at which point we may as well check the |
@@ -1924,7 +1957,10 @@ async def _send_dummy_events_to_fill_extremities(self) -> None: |
1924 | 1957 | ) |
1925 | 1958 |
|
1926 | 1959 | for room_id in room_ids: |
1927 | | - dummy_event_sent = await self._send_dummy_event_for_room(room_id) |
| 1960 | + async with self._worker_lock_handler.acquire_read_write_lock( |
| 1961 | + DELETE_ROOM_LOCK_NAME, room_id, write=False |
| 1962 | + ): |
| 1963 | + dummy_event_sent = await self._send_dummy_event_for_room(room_id) |
1928 | 1964 |
|
1929 | 1965 | if not dummy_event_sent: |
1930 | 1966 | # Did not find a valid user in the room, so remove from future attempts |
|
0 commit comments