Cloud backend: suppress unhandled TaskStopped exceptions from FileBodyProducer.
authorDaira Hopwood <david-sarah@jacaranda.org>
Tue, 28 May 2013 21:33:22 +0000 (22:33 +0100)
committerDaira Hopwood <daira@jacaranda.org>
Tue, 4 Aug 2015 18:10:28 +0000 (19:10 +0100)
Signed-off-by: Daira Hopwood <david-sarah@jacaranda.org>
src/allmydata/storage/backends/cloud/cloud_common.py

index 90fec844e64d090fd8b58d5d48101f20b9c9844f..e122dd1c466c085d1de0522f0f94fd88885a6be6 100644 (file)
@@ -652,6 +652,18 @@ class DataCollector(Protocol):
         return self._done
 
 
+class QuieterFileBodyProducer(FileBodyProducer):
+    """
+    Workaround for a minor bug in Twisted: losing a connection may result in stopProducing
+    being called twice, causing a spurious unhandled TaskStopped exception to be logged.
+    """
+    def stopProducing(self):
+        try:
+            FileBodyProducer.stopProducing(self)
+        except task.TaskStopped:
+            log.msg("ignoring a harmless TaskStopped exception", level=log.OPERATIONAL)
+
+
 class HTTPClientMixin:
     """
     I implement helper methods for making HTTP requests and getting response headers.
@@ -671,7 +683,7 @@ class HTTPClientMixin:
         if body is None:
             bodyProducer = None
         else:
-            bodyProducer = FileBodyProducer(StringIO(body))
+            bodyProducer = QuieterFileBodyProducer(StringIO(body))
             # We don't need to explicitly set Content-Length because FileBodyProducer knows the length
             # (and if we do it won't work, because in that case Content-Length would be duplicated).