From: Ben Darnell Date: Mon, 19 Nov 2012 02:35:36 +0000 (-0500) Subject: Remove redundant logging of read errors in IOStream. X-Git-Tag: v3.0.0~217 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26078cdb40b74ac9e92817774600d99d5124bd29;p=thirdparty%2Ftornado.git Remove redundant logging of read errors in IOStream. The logging in read_from_fd is generally redundant with logging at higher levels - the error would be logged again in _handle_read, or propagated from _try_inline_read. Closes #632. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 7f6ba7cac..40ac4964f 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -399,8 +399,6 @@ class BaseIOStream(object): # be available on self.error for apps that care). self.close() return - gen_log.warning("Read error on %d: %s", - self.fileno(), e) self.close() raise if chunk is None: diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 1177adbfc..28c1b78b0 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -390,6 +390,39 @@ class TestIOStreamMixin(object): server.close() client.close() + def test_inline_read_error(self): + # An error on an inline read is raised without logging (on the + # assumption that it will eventually be noticed or logged further + # up the stack). + server, client = self.make_iostream_pair() + try: + os.close(server.socket.fileno()) + with self.assertRaises(socket.error): + server.read_bytes(1, lambda data: None) + finally: + server.close() + client.close() + + def test_async_read_error_logging(self): + # Socket errors on asynchronous reads should be logged (but only + # once). + server, client = self.make_iostream_pair() + server.set_close_callback(self.stop) + try: + # Start a read that will be fullfilled asynchronously. + server.read_bytes(1, lambda data: None) + client.write(b('a')) + # Stub out read_from_fd to make it fail. + def fake_read_from_fd(): + os.close(server.socket.fileno()) + server.__class__.read_from_fd(server) + server.read_from_fd = fake_read_from_fd + # This log message is from _handle_read (not read_from_fd). + with ExpectLog(gen_log, "error on read"): + self.wait() + finally: + server.close() + client.close() class TestIOStreamWebHTTP(TestIOStreamWebMixin, AsyncHTTPTestCase): def _make_client_iostream(self):