element-hq / element-hq/synapse
SyncRestServlet runs into errors when using the ModuleAPI to delete rooms
- Dominant language
- Python
- Stars
- 4.6k
- Forks
- 600
- Avg merge
- 5d 22h
- Merged PRs (30d)
- 51
Description
### Description
I am running into a very racey error when calling the ModuleAPIs `delete_room`-Method with an active client. The error causes the `matrix-js-sdk` to keep the deleted room in the IndexedDB leading to confusing errors.
### Steps to reproduce
- create a module that uses the delete_room method
- create a new room on the server
- trigger `delete_room` while a client is syncing
*This only happens about 1 out of 10 times*
### Homeserver
Private homeserver
### Synapse Version
1.128.0
### Installation Method
Docker (matrixdotorg/synapse)
### Database
Single PostgreSQL without previous backup or portdb
### Workers
Single process
### Platform
The homeserver is running as a docker container on a debian server.
### Configuration
```
require_auth_for_profile_requests: true
delete_stale_devices_after: '14d'
forgotten_room_retention_period: '1d'
allow_per_room_profiles: false
forget_rooms_on_leave: true
redaction_retention_period: 0
presence:
enabled: true
auto_accept_invites:
enabled: true
only_for_direct_messages: false
only_from_local_users: false
modules:
- module:
```
### Relevant log output
```shell
2025-06-11 06:59:03,203 - synapse.http.server - 146 - ERROR - GET-599 - Failed handle request via 'SyncRestServlet':
Traceback (most recent call last):
File "/usr/local/lib/python3.12/site-packages/twisted/internet/defer.py", line 2014, in _inlineCallbacks
result = context.run(gen.send, result)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/util/caches/response_cache.py", line 265, in cb
return await callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/handlers/sync.py", line 590, in _wait_for_sync_for_user
result = await self.notifier.wait_for_events(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/notifier.py", line 658, in wait_for_events
result = await callback(prev_token, current_token)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/handlers/sync.py", line 586, in current_sync_callback
return await self.current_sync_for_user(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/handlers/sync.py", line 676, in current_sync_for_user
] = await self.generate_sync_result(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/handlers/sync.py", line 1868, in generate_sync_result
) = await self._generate_sync_entry_for_rooms(sync_result_builder)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/handlers/sync.py", line 2442, in _generate_sync_entry_for_rooms
room_changes = await self._get_room_changes_for_incremental_sync(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/handlers/sync.py", line 2612, in _get_room_changes_for_incremental_sync
await self._state_storage_controller.get_state_ids_at(
File "/usr/local/lib/python3.12/site-packages/synapse/storage/controllers/state.py", line 457, in get_state_ids_at
state = await self.get_state_after_event(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.12/site-packages/synapse/storage/controllers/state.py", line 416, in get_state_after_event
m = (await self.stores.main.get_metadata_for_events([event_id]))[event_id]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^
KeyError: '$kY2fSU2v1qMeS6kKuVacFczli6Il2MALQnrq_1wxW2Y'
```
### Anything else that would be useful to know?
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.