From: Ben Darnell Date: Mon, 19 May 2014 00:20:29 +0000 (-0400) Subject: Raise StreamClosedError instead of IOError for ECONNRESET. X-Git-Tag: v4.0.0b1~60 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5a9333d5062dde87c92078482caceb2bef43aa9f;p=thirdparty%2Ftornado.git 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) --- 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