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

Commit 3e58ce7

Browse files
Don't bother responding to client requests that have already disconnected (#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
1 parent 785437d commit 3e58ce7

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

changelog.d/8465.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Don't attempt to respond to some requests if the client has already disconnected.

synapse/http/server.py

+5
Original file line numberDiff line numberDiff line change
@@ -651,6 +651,11 @@ def respond_with_json_bytes(
651651
Returns:
652652
twisted.web.server.NOT_DONE_YET if the request is still active.
653653
"""
654+
if request._disconnected:
655+
logger.warning(
656+
"Not sending response to request %s, already disconnected.", request
657+
)
658+
return
654659

655660
request.setResponseCode(code)
656661
request.setHeader(b"Content-Type", b"application/json")

synapse/rest/media/v1/_base.py

+6
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ async def respond_with_responder(
213213
file_size (int|None): Size in bytes of the media. If not known it should be None
214214
upload_name (str|None): The name of the requested file, if any.
215215
"""
216+
if request._disconnected:
217+
logger.warning(
218+
"Not sending response to request %s, already disconnected.", request
219+
)
220+
return
221+
216222
if not responder:
217223
respond_404(request)
218224
return

0 commit comments

Comments
 (0)