summary refs log tree commit diff
path: root/synapse
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2018-01-16 17:58:16 +0000
committerRichard van der Hoff <richard@matrix.org>2018-01-16 17:58:16 +0000
commit936482d507ffbf59d9aee58f851ec6ff2a120424 (patch)
treed679e611062bef045199fe38f933c4de1d3ffdda /synapse
parentMerge pull request #2785 from matrix-org/rav/reorganise_metrics_again (diff)
downloadsynapse-936482d507ffbf59d9aee58f851ec6ff2a120424.tar.xz
Fix 'NoneType' object has no attribute 'writeHeaders'
Avoid throwing a (harmless) exception when we try to write an error response to
an http request where the client has disconnected.

This comes up as a CRITICAL error in the logs which tends to mislead people
into thinking there's an actual problem
Diffstat (limited to 'synapse')
-rw-r--r--synapse/http/server.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/synapse/http/server.py b/synapse/http/server.py
index 269b65ca41..8077e22794 100644
--- a/synapse/http/server.py
+++ b/synapse/http/server.py
@@ -316,15 +316,6 @@ class JsonResource(HttpServer, resource.Resource):
 
     def _send_response(self, request, code, response_json_object,
                        response_code_message=None):
-        # could alternatively use request.notifyFinish() and flip a flag when
-        # the Deferred fires, but since the flag is RIGHT THERE it seems like
-        # a waste.
-        if request._disconnected:
-            logger.warn(
-                "Not sending response to request %s, already disconnected.",
-                request)
-            return
-
         outgoing_responses_counter.inc(request.method, str(code))
 
         # TODO: Only enable CORS for the requests that need it.
@@ -400,6 +391,15 @@ class RootRedirect(resource.Resource):
 def respond_with_json(request, code, json_object, send_cors=False,
                       response_code_message=None, pretty_print=False,
                       version_string="", canonical_json=True):
+    # could alternatively use request.notifyFinish() and flip a flag when
+    # the Deferred fires, but since the flag is RIGHT THERE it seems like
+    # a waste.
+    if request._disconnected:
+        logger.warn(
+            "Not sending response to request %s, already disconnected.",
+            request)
+        return
+
     if pretty_print:
         json_bytes = encode_pretty_printed_json(json_object) + "\n"
     else: