summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard van der Hoff <richard@matrix.org>2019-02-01 12:22:57 +0000
committerRichard van der Hoff <richard@matrix.org>2019-02-01 12:22:57 +0000
commitf0ba34f581906e3809de6313bc48b696ac4ef07c (patch)
treec04e300201ca4999ee31b2ad6bae2665fed8c061
parentv0.99.0rc3 (diff)
downloadsynapse-f0ba34f581906e3809de6313bc48b696ac4ef07c.tar.xz
Fix noisy "twisted.internet.task.TaskStopped" errors in logs
Fixes #4003
-rw-r--r--changelog.d/4546.bugfix1
-rw-r--r--synapse/http/matrixfederationclient.py17
2 files changed, 16 insertions, 2 deletions
diff --git a/changelog.d/4546.bugfix b/changelog.d/4546.bugfix
new file mode 100644
index 0000000000..056f2848ed
--- /dev/null
+++ b/changelog.d/4546.bugfix
@@ -0,0 +1 @@
+Fix noisy "twisted.internet.task.TaskStopped" errors in logs
diff --git a/synapse/http/matrixfederationclient.py b/synapse/http/matrixfederationclient.py
index bb2e64ed80..5ee4d528d2 100644
--- a/synapse/http/matrixfederationclient.py
+++ b/synapse/http/matrixfederationclient.py
@@ -28,7 +28,7 @@ from canonicaljson import encode_canonical_json
 from prometheus_client import Counter
 from signedjson.sign import sign_json
 
-from twisted.internet import defer, protocol
+from twisted.internet import defer, protocol, task
 from twisted.internet.error import DNSLookupError
 from twisted.internet.task import _EPSILON, Cooperator
 from twisted.web._newclient import ResponseDone
@@ -286,7 +286,7 @@ class MatrixFederationHttpClient(object):
                             json,
                         )
                         data = encode_canonical_json(json)
-                        producer = FileBodyProducer(
+                        producer = QuieterFileBodyProducer(
                             BytesIO(data),
                             cooperator=self._cooperator,
                         )
@@ -839,3 +839,16 @@ def encode_query_args(args):
     query_bytes = urllib.parse.urlencode(encoded_args, True)
 
     return query_bytes.encode('utf8')
+
+
+class QuieterFileBodyProducer(FileBodyProducer):
+    """Wrapper for FileBodyProducer that avoids CRITICAL errors when the connection drops.
+
+    Workaround for https://github.com/matrix-org/synapse/issues/4003 /
+    https://twistedmatrix.com/trac/ticket/6528
+    """
+    def stopProducing(self):
+        try:
+            FileBodyProducer.stopProducing(self)
+        except task.TaskStopped:
+            pass