From 5a9333d5062dde87c92078482caceb2bef43aa9f Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Sun, 18 May 2014 20:20:29 -0400 Subject: [PATCH] Raise StreamClosedError instead of IOError for ECONNRESET. 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 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tornado/iostream.py b/tornado/iostream.py index e6885b6a7..2836cbfc0 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -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 -- 2.47.3