This repository has been archived by the owner on Apr 26, 2024. It is now read-only.
Don't prune cache entries for get_or_create_notice_room_for_user
#12712
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #12686
Before this change, if the homeserver had an MAU limit set and time-based cache expiry turned on, Synapse would recreate a server notice room for every user who wouldn't sync for more than the configured cache entry TTL. If that TTL is low (e.g. 10min, for resource management reasons), this means loads of empty rooms can be created, filling up the homeserver's database with garbage.
The reason this happens is because, if an MAU limit is set, Synapse will check every time a user syncs whether the user should be notified about the limit being reached. This is done by calling
get_or_create_notice_room_for_user
, which looks up (and creates if necessary) a server notice room for the user, though without inviting them to it right away (so that the user is only invited when there's something to notify them about). That method is cached, but if the cache entry TTL is set to a low value and the user doesn't sync often enough the entry expires. At which point Synapse realises there isn't a room created by the server notice user with the user either invited or joined, and creates another.Ideally we should persist the server notice rooms to the database rather than store them in an in-memory cache, because even with this change we're still creating new rooms after a restart. I didn't have the time to correctly think about every edge case of the database migration this would require (e.g. what to do about servers with existing server notice rooms but that don't have the feature enabled anymore, etc). Though this change will still be good to have in a world where we persist that data, so it's a good first step regardless. I'll open an issue about it so it's tracked somewhere.