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

Commit

Permalink
Don't bother responding to client requests that have already disconne…
Browse files Browse the repository at this point in the history
…cted (#8465)

This PR ports the quick fix from #2796 to further methods which handle media, URL preview and `/key/v2/server` requests. This prevents a harmless `ERROR` that comes up in the logs when we were unable to respond to a client request when the client had already disconnected. In this case we simply bail out if the client has already done so.

This is the 'simple fix' as suggested by #5304 (comment).

Fixes #6700
Fixes #5304
  • Loading branch information
anoadragon453 authored Oct 6, 2020
1 parent 785437d commit 3e58ce7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/8465.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Don't attempt to respond to some requests if the client has already disconnected.
5 changes: 5 additions & 0 deletions synapse/http/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,11 @@ def respond_with_json_bytes(
Returns:
twisted.web.server.NOT_DONE_YET if the request is still active.
"""
if request._disconnected:
logger.warning(
"Not sending response to request %s, already disconnected.", request
)
return

request.setResponseCode(code)
request.setHeader(b"Content-Type", b"application/json")
Expand Down
6 changes: 6 additions & 0 deletions synapse/rest/media/v1/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ async def respond_with_responder(
file_size (int|None): Size in bytes of the media. If not known it should be None
upload_name (str|None): The name of the requested file, if any.
"""
if request._disconnected:
logger.warning(
"Not sending response to request %s, already disconnected.", request
)
return

if not responder:
respond_404(request)
return
Expand Down

0 comments on commit 3e58ce7

Please sign in to comment.