diff options
author | Nick Mills-Barrett <nick@beeper.com> | 2022-07-19 13:25:29 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-19 11:25:29 +0000 |
commit | 2ee0b6ef4b78bada535beb30301cf0e01cbb7d81 (patch) | |
tree | 763ff882ab3a25d50bdf9b5168b162261f0666c3 /synapse/storage/_base.py | |
parent | Increase batch size of `bulk_get_push_rules` and `_get_joined_profiles_from_e... (diff) | |
download | synapse-2ee0b6ef4b78bada535beb30301cf0e01cbb7d81.tar.xz |
Safe async event cache (#13308)
Fix race conditions in the async cache invalidation logic, by separating the async & local invalidation calls and ensuring any async call i executed first. Signed off by Nick @ Beeper (@Fizzadar).
Diffstat (limited to 'synapse/storage/_base.py')
-rw-r--r-- | synapse/storage/_base.py | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/synapse/storage/_base.py b/synapse/storage/_base.py index b8c8dcd76b..a2f8310388 100644 --- a/synapse/storage/_base.py +++ b/synapse/storage/_base.py @@ -96,6 +96,10 @@ class SQLBaseStore(metaclass=ABCMeta): cache doesn't exist. Mainly used for invalidating caches on workers, where they may not have the cache. + Note that this function does not invalidate any remote caches, only the + local in-memory ones. Any remote invalidation must be performed before + calling this. + Args: cache_name key: Entry to invalidate. If None then invalidates the entire @@ -112,7 +116,10 @@ class SQLBaseStore(metaclass=ABCMeta): if key is None: cache.invalidate_all() else: - cache.invalidate(tuple(key)) + # Prefer any local-only invalidation method. Invalidating any non-local + # cache must be be done before this. + invalidate_method = getattr(cache, "invalidate_local", cache.invalidate) + invalidate_method(tuple(key)) def db_to_json(db_content: Union[memoryview, bytes, bytearray, str]) -> Any: |