Skip to content
Snippets Groups Projects
Unverified Commit 3e58ce72 authored by Andrew Morgan's avatar Andrew Morgan Committed by GitHub
Browse files

Don't bother responding to client requests that have already disconnected (#8465)

This PR ports the quick fix from https://github.com/matrix-org/synapse/pull/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 https://github.com/matrix-org/synapse/issues/5304#issuecomment-574740003.

Fixes https://github.com/matrix-org/synapse/issues/6700
Fixes https://github.com/matrix-org/synapse/issues/5304
parent 785437dc
No related branches found
No related tags found
No related merge requests found
Don't attempt to respond to some requests if the client has already disconnected.
\ No newline at end of file
...@@ -651,6 +651,11 @@ def respond_with_json_bytes( ...@@ -651,6 +651,11 @@ def respond_with_json_bytes(
Returns: Returns:
twisted.web.server.NOT_DONE_YET if the request is still active. 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.setResponseCode(code)
request.setHeader(b"Content-Type", b"application/json") request.setHeader(b"Content-Type", b"application/json")
......
...@@ -213,6 +213,12 @@ async def respond_with_responder( ...@@ -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 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. 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: if not responder:
respond_404(request) respond_404(request)
return return
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment