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

Add @cancellable decorator, for use on endpoint methods that can be cancelled when clients disconnect #12583

Closed
wants to merge 21 commits into from

Commits on Apr 28, 2022

  1. Add @cancellable decorator, for use on request handlers

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    2780bed View commit details
    Browse the repository at this point in the history
  2. Improve logging for cancelled requests

    Don't log stack traces for cancelled requests and use a custom HTTP
    status code of 499.
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    1ce7dbf View commit details
    Browse the repository at this point in the history
  3. Add ability to cancel disconnected requests to SynapseRequest

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    0dc4178 View commit details
    Browse the repository at this point in the history
  4. Capture the Deferred for request cancellation in _AsyncResource

    All async request processing goes through `_AsyncResource`, so this is
    the only place where a `Deferred` needs to be captured for cancellation.
    
    Unfortunately, the same isn't true for determining whether a request
    can be cancelled. Each of `RestServlet`, `BaseFederationServlet`,
    `DirectServe{Html,Json}Resource` and `ReplicationEndpoint` have
    different wrappers around the method doing the request handling and they
    all need to be handled separately.
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    5a9991c View commit details
    Browse the repository at this point in the history
  5. Respect the @cancellable flag for DirectServe{Html,Json}Resources

    `DirectServeHtmlResource` and `DirectServeJsonResource` both inherit
    from `_AsyncResource`. These classes expect to be subclassed with
    `_async_render_*` methods.
    
    This commit has no effect on `JsonResource`, despite inheriting from
    `_AsyncResource`. `JsonResource` has its own `_async_render` override
    which will need to be updated separately.
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    46cdb4b View commit details
    Browse the repository at this point in the history
  6. Respect the @cancellable flag for RestServlets and `BaseFederatio…

    …nServlet`s
    
    Both `RestServlet`s and `BaseFederationServlet`s register their handlers
    with `HttpServer.register_paths` / `JsonResource.register_paths`. Update
    `JsonResource` to respect the `@cancellable` flag on handlers registered
    in this way.
    
    Although `ReplicationEndpoint` also registers itself using
    `register_paths`, it does not pass the handler method that would have the
    `@cancellable` flag directly, and so needs separate handling.
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    2326bbf View commit details
    Browse the repository at this point in the history
  7. Complain if a federation endpoint has the @cancellable flag

    `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]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    c3eb1e3 View commit details
    Browse the repository at this point in the history
  8. Respect the @cancellable flag for ReplicationEndpoints

    While `ReplicationEndpoint`s register themselves via `JsonResource`,
    they pass a method that calls the handler, instead of the handler itself,
    to `register_paths`. As a result, `JsonResource` will not correctly pick
    up the `@cancellable` flag and we have to apply it ourselves.
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    62d3b91 View commit details
    Browse the repository at this point in the history
  9. Expose the SynapseRequest from FakeChannel for testing disconnection

    In order to simulate a client disconnection in tests, we would like to
    call `Request.connectionLost`. Make the `Request` accessible from the
    `FakeChannel` returned by `make_request`.
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    3d89472 View commit details
    Browse the repository at this point in the history
  10. Add helper class for testing request cancellation

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    2bbad29 View commit details
    Browse the repository at this point in the history
  11. Test the @cancellable flag on RestServlet methods

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    6720b87 View commit details
    Browse the repository at this point in the history
  12. Test the @cancellable flag on DirectServe{Html,Json}Resource methods

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    92b7b17 View commit details
    Browse the repository at this point in the history
  13. Test the @cancellable flag on ReplicationEndpoint._handle_request

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    d3f75f3 View commit details
    Browse the repository at this point in the history
  14. Fix make_signed_federation_request turning empty dicts into b""

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    3544cfd View commit details
    Browse the repository at this point in the history
  15. Test the @cancellable flag on BaseFederationServlet methods

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    89cb0f1 View commit details
    Browse the repository at this point in the history
  16. Disable tests for the @cancellable flag on BaseFederationServlet

    …methods
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    342a502 View commit details
    Browse the repository at this point in the history
  17. Add newsfile

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed Apr 28, 2022
    Configuration menu
    Copy the full SHA
    a89fc72 View commit details
    Browse the repository at this point in the history

Commits on May 6, 2022

  1. Don't trash the logging context when cancelling request processing

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed May 6, 2022
    Configuration menu
    Copy the full SHA
    3f8a59f View commit details
    Browse the repository at this point in the history
  2. Rename to EndpointCancellationTestCase to `EndpointCancellationTest…

    …HelperMixin`
    
    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed May 6, 2022
    Configuration menu
    Copy the full SHA
    08acc0c View commit details
    Browse the repository at this point in the history
  3. Add missing docstring for expected_body parameter

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed May 6, 2022
    Configuration menu
    Copy the full SHA
    4976ae5 View commit details
    Browse the repository at this point in the history
  4. Improve assertion message when await_result=False is forgotten

    Signed-off-by: Sean Quah <[email protected]>
    Sean Quah committed May 6, 2022
    Configuration menu
    Copy the full SHA
    4e644ea View commit details
    Browse the repository at this point in the history