Skip to content

Commit aee1076

Browse files
committed
Revert "Fix matrix-org#8518 (sync requests being cached wrongly on timeout) (matrix-org#9358)"
This reverts commit f5c93fc. This is being backed out due to a regression (matrix-org#9507) and additional review feedback being provided.
1 parent 7f5d753 commit aee1076

File tree

3 files changed

+3
-35
lines changed

3 files changed

+3
-35
lines changed

changelog.d/9358.misc

Lines changed: 0 additions & 1 deletion
This file was deleted.

synapse/handlers/sync.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,8 @@ async def wait_for_sync_for_user(
277277
user_id = sync_config.user.to_string()
278278
await self.auth.check_auth_blocking(requester=requester)
279279

280-
res = await self.response_cache.wrap_conditional(
280+
res = await self.response_cache.wrap(
281281
sync_config.request_key,
282-
lambda result: since_token != result.next_batch,
283282
self._wait_for_sync_for_user,
284283
sync_config,
285284
since_token,

synapse/util/caches/response_cache.py

Lines changed: 2 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# See the License for the specific language governing permissions and
1414
# limitations under the License.
1515
import logging
16-
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Optional, Set, TypeVar
16+
from typing import TYPE_CHECKING, Any, Callable, Dict, Generic, Optional, TypeVar
1717

1818
from twisted.internet import defer
1919

@@ -40,7 +40,6 @@ class ResponseCache(Generic[T]):
4040
def __init__(self, hs: "HomeServer", name: str, timeout_ms: float = 0):
4141
# Requests that haven't finished yet.
4242
self.pending_result_cache = {} # type: Dict[T, ObservableDeferred]
43-
self.pending_conditionals = {} # type: Dict[T, Set[Callable[[Any], bool]]]
4443

4544
self.clock = hs.get_clock()
4645
self.timeout_sec = timeout_ms / 1000.0
@@ -102,11 +101,7 @@ def set(self, key: T, deferred: defer.Deferred) -> defer.Deferred:
102101
self.pending_result_cache[key] = result
103102

104103
def remove(r):
105-
should_cache = all(
106-
func(r) for func in self.pending_conditionals.pop(key, [])
107-
)
108-
109-
if self.timeout_sec and should_cache:
104+
if self.timeout_sec:
110105
self.clock.call_later(
111106
self.timeout_sec, self.pending_result_cache.pop, key, None
112107
)
@@ -117,31 +112,6 @@ def remove(r):
117112
result.addBoth(remove)
118113
return result.observe()
119114

120-
def add_conditional(self, key: T, conditional: Callable[[Any], bool]):
121-
self.pending_conditionals.setdefault(key, set()).add(conditional)
122-
123-
def wrap_conditional(
124-
self,
125-
key: T,
126-
should_cache: Callable[[Any], bool],
127-
callback: "Callable[..., Any]",
128-
*args: Any,
129-
**kwargs: Any
130-
) -> defer.Deferred:
131-
"""The same as wrap(), but adds a conditional to the final execution.
132-
133-
When the final execution completes, *all* conditionals need to return True for it to properly cache,
134-
else it'll not be cached in a timed fashion.
135-
"""
136-
137-
# See if there's already a result on this key that hasn't yet completed. Due to the single-threaded nature of
138-
# python, adding a key immediately in the same execution thread will not cause a race condition.
139-
result = self.get(key)
140-
if not result or isinstance(result, defer.Deferred) and not result.called:
141-
self.add_conditional(key, should_cache)
142-
143-
return self.wrap(key, callback, *args, **kwargs)
144-
145115
def wrap(
146116
self, key: T, callback: "Callable[..., Any]", *args: Any, **kwargs: Any
147117
) -> defer.Deferred:

0 commit comments

Comments
 (0)