summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthew Ma <mtthman@amazon.com>2023-08-17 02:22:50 -0700
committerGitHub <noreply@github.com>2023-08-17 10:22:50 +0100
commit8a4fb7a6baf32a35c24056474d98fed525522b78 (patch)
treef019ae3e7cb04062ee4973be3e5d2dc3d1da6543
parentRename pagination&purge locks and add comments explaining them (#16112) (diff)
downloadsynapse-8a4fb7a6baf32a35c24056474d98fed525522b78.tar.xz
Disable caching in /sync corner case (#16080)
Fixes #15502
-rw-r--r--changelog.d/16080.bugfix1
-rw-r--r--synapse/handlers/sync.py20
2 files changed, 11 insertions, 10 deletions
diff --git a/changelog.d/16080.bugfix b/changelog.d/16080.bugfix
new file mode 100644
index 0000000000..1ad6fb3c52
--- /dev/null
+++ b/changelog.d/16080.bugfix
@@ -0,0 +1 @@
+Fix a long-standing bu in `/sync` where timeout=0 does not skip caching, resulting in slow calls in cases where there are no new changes. Contributed by @PlasmaIntec.
\ No newline at end of file
diff --git a/synapse/handlers/sync.py b/synapse/handlers/sync.py
index 8174248387..60a9f341b5 100644
--- a/synapse/handlers/sync.py
+++ b/synapse/handlers/sync.py
@@ -387,16 +387,16 @@ class SyncHandler:
                 from_token=since_token,
             )
 
-            # if nothing has happened in any of the users' rooms since /sync was called,
-            # the resultant next_batch will be the same as since_token (since the result
-            # is generated when wait_for_events is first called, and not regenerated
-            # when wait_for_events times out).
-            #
-            # If that happens, we mustn't cache it, so that when the client comes back
-            # with the same cache token, we don't immediately return the same empty
-            # result, causing a tightloop. (#8518)
-            if result.next_batch == since_token:
-                cache_context.should_cache = False
+        # if nothing has happened in any of the users' rooms since /sync was called,
+        # the resultant next_batch will be the same as since_token (since the result
+        # is generated when wait_for_events is first called, and not regenerated
+        # when wait_for_events times out).
+        #
+        # If that happens, we mustn't cache it, so that when the client comes back
+        # with the same cache token, we don't immediately return the same empty
+        # result, causing a tightloop. (#8518)
+        if result.next_batch == since_token:
+            cache_context.should_cache = False
 
         if result:
             if sync_config.filter_collection.lazy_load_members():