]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Raise StreamClosedError instead of IOError for ECONNRESET.
authorBen Darnell <ben@bendarnell.com>
Mon, 19 May 2014 00:20:29 +0000 (20:20 -0400)
committerBen Darnell <ben@bendarnell.com>
Mon, 19 May 2014 00:20:29 +0000 (20:20 -0400)
This allows application code to only catch one kind of exception
(an ECONNRESET exception is raised from
tornado.test.httpserver_test.KeepAliveTest.test_pipeline_cancel
on linux but not on mac)

tornado/iostream.py

index e6885b6a7789d4c41e7593b4dd1dc66cb9c7c803..2836cbfc00837d97c2c67880fe37278f74c2e549 100644 (file)
@@ -365,7 +365,14 @@ class BaseIOStream(object):
                 futures.append(self._connect_future)
                 self._connect_future = None
             for future in futures:
-                future.set_exception(self.error or StreamClosedError())
+                if (isinstance(self.error, (socket.error, IOError)) and
+                    errno_from_exception(self.error) in _ERRNO_CONNRESET):
+                    # Treat connection resets as closed connections so
+                    # clients only have to catch one kind of exception
+                    # to avoid logging.
+                    future.set_exception(StreamClosedError())
+                else:
+                    future.set_exception(self.error or StreamClosedError())
             if self._close_callback is not None:
                 cb = self._close_callback
                 self._close_callback = None