mirror of
https://github.com/element-hq/synapse.git
synced 2024-11-22 17:46:08 +03:00
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.
This commit is contained in:
parent
ff22672fd6
commit
4876af06dd
2 changed files with 7 additions and 0 deletions
1
changelog.d/7930.feature
Normal file
1
changelog.d/7930.feature
Normal file
|
@ -0,0 +1 @@
|
|||
Abort federation requests where the client disconnects before the ratelimiter expires.
|
|
@ -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
|
||||
)
|
||||
|
|
Loading…
Reference in a new issue