Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit 6ee61b9

Browse files
authored
Complain if a federation endpoint has the @cancellable flag (#12705)
`BaseFederationServlet` wraps its endpoints in a bunch of async code that has not been vetted for compatibility with cancellation. Fail CI if a `@cancellable` flag is applied to a federation endpoint. Signed-off-by: Sean Quah <[email protected]>
1 parent d38d242 commit 6ee61b9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

changelog.d/12705.misc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Complain if a federation endpoint has the `@cancellable` flag, since some of the wrapper code may not handle cancellation correctly yet.

synapse/federation/transport/server/_base.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
from synapse.api.errors import Codes, FederationDeniedError, SynapseError
2323
from synapse.api.urls import FEDERATION_V1_PREFIX
24-
from synapse.http.server import HttpServer, ServletCallback
24+
from synapse.http.server import HttpServer, ServletCallback, is_method_cancellable
2525
from synapse.http.servlet import parse_json_object_from_request
2626
from synapse.http.site import SynapseRequest
2727
from synapse.logging.context import run_in_background
@@ -373,6 +373,17 @@ def register(self, server: HttpServer) -> None:
373373
if code is None:
374374
continue
375375

376+
if is_method_cancellable(code):
377+
# The wrapper added by `self._wrap` will inherit the cancellable flag,
378+
# but the wrapper itself does not support cancellation yet.
379+
# Once resolved, the cancellation tests in
380+
# `tests/federation/transport/server/test__base.py` can be re-enabled.
381+
raise Exception(
382+
f"{self.__class__.__name__}.on_{method} has been marked as "
383+
"cancellable, but federation servlets do not support cancellation "
384+
"yet."
385+
)
386+
376387
server.register_paths(
377388
method,
378389
(pattern,),

tests/federation/transport/server/test__base.py

+2
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ class BaseFederationServletCancellationTests(
5959
):
6060
"""Tests for `BaseFederationServlet` cancellation."""
6161

62+
skip = "`BaseFederationServlet` does not support cancellation yet."
63+
6264
path = f"{CancellableFederationServlet.PREFIX}{CancellableFederationServlet.PATH}"
6365

6466
def create_test_resource(self):

0 commit comments

Comments
 (0)