From: Roey Berman Date: Thu, 12 Jul 2012 16:57:38 +0000 (+0300) Subject: Fixed and added regression test for a bug that was introduced in 2.3 X-Git-Tag: v2.4.0~40 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5edd8daf3c43bdb874a80645b53147e254081740;p=thirdparty%2Ftornado.git Fixed and added regression test for a bug that was introduced in 2.3 where the IOStream._close_callback would never be called if there were pending reads. (Cherry-picked from https://github.com/facebook/tornado/pull/561 with amendments for compatibility with python 2.5-2.6 -bdarnell) Closes #561. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index cfe6b1ce8..5297f15a0 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -390,7 +390,7 @@ class IOStream(object): self._pending_callbacks -= 1 if self._read_from_buffer(): return - self._add_io_state(self.io_loop.READ) + self._maybe_add_error_listener() def _read_from_socket(self): """Attempts to read from the socket. diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 4bb4f21ce..68b5f26ae 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -251,3 +251,26 @@ class TestIOStream(AsyncHTTPTestCase, LogTrapTestCase): finally: server.close() client.close() + + def test_close_callback_with_pending_read(self): + # Regression test for a bug that was introduced in 2.3 + # where the IOStream._close_callback would never be called + # if there were pending reads. + OK = b("OK\r\n") + server, client = self.make_iostream_pair() + client.set_close_callback(self.stop) + try: + server.write(OK, server.close) + client.read_until(b("\r\n"), self.stop) + res = self.wait() + self.assertEqual(res, OK) + + client.read_until(b("\r\n"), lambda x: x) + # If _close_callback (self.stop) is not called, + # an AssertionError: Async operation timed out after 5 seconds + # will be raised. + res = self.wait() + self.assertTrue(res is None) + finally: + server.close() + client.close()