From 511fbcbff50f1175620c3f8ecc9492356ad2a6ba Mon Sep 17 00:00:00 2001 From: Daira Hopwood Date: Tue, 28 May 2013 22:33:22 +0100 Subject: [PATCH] Cloud backend: suppress unhandled TaskStopped exceptions from FileBodyProducer. Signed-off-by: Daira Hopwood --- .../storage/backends/cloud/cloud_common.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/allmydata/storage/backends/cloud/cloud_common.py b/src/allmydata/storage/backends/cloud/cloud_common.py index 90fec844..e122dd1c 100644 --- a/src/allmydata/storage/backends/cloud/cloud_common.py +++ b/src/allmydata/storage/backends/cloud/cloud_common.py @@ -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). -- 2.45.2