diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2020-07-23 16:52:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-23 16:52:33 +0100 |
commit | 4876af06ddb280b0a01903c1da17466b13124eb3 (patch) | |
tree | f1a70f5da23165234a196eddbbdda6f8a0079f04 | |
parent | Reorder database docs to promote postgresql. (#7933) (diff) | |
download | synapse-4876af06ddb280b0a01903c1da17466b13124eb3.tar.xz |
Abort federation requests if the client disconnects early (#7930)
For inbound federation requests, if a given remote server makes too many requests at once, we start stacking them up rather than processing them immediatedly. However, that means that there is a fair chance that the requesting server will disconnect before we start processing the request. In that case, if it was a read-only request (ie, a GET request), there is absolutely no point in building a response (and some requests are quite expensive to handle). Even in the case of a POST request, one of two things will happen: * Most likely, the requesting server will retry the request and we'll get the information anyway. * Even if it doesn't, the requesting server has to assume that we didn't get the memo, and act accordingly. In short, we're better off aborting the request at this point rather than ploughing on with what might be a quite expensive request.
-rw-r--r-- | changelog.d/7930.feature | 1 | ||||
-rw-r--r-- | synapse/federation/transport/server.py | 6 |
2 files changed, 7 insertions, 0 deletions
diff --git a/changelog.d/7930.feature b/changelog.d/7930.feature new file mode 100644 index 0000000000..a27e4812da --- /dev/null +++ b/changelog.d/7930.feature @@ -0,0 +1 @@ +Abort federation requests where the client disconnects before the ratelimiter expires. diff --git a/synapse/federation/transport/server.py b/synapse/federation/transport/server.py index 24f7d4b3bc..5e111aa902 100644 --- a/synapse/federation/transport/server.py +++ b/synapse/federation/transport/server.py @@ -338,6 +338,12 @@ class BaseFederationServlet(object): if origin: with ratelimiter.ratelimit(origin) as d: await d + if request._disconnected: + logger.warning( + "client disconnected before we started processing " + "request" + ) + return -1, None response = await func( origin, content, request.args, *args, **kwargs ) |