]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fixed and added regression test for a bug that was introduced in 2.3
authorRoey Berman <roey.berman@gmail.com>
Thu, 12 Jul 2012 16:57:38 +0000 (19:57 +0300)
committerBen Darnell <ben@bendarnell.com>
Sat, 14 Jul 2012 17:54:27 +0000 (18:54 +0100)
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.

tornado/iostream.py
tornado/test/iostream_test.py

index cfe6b1ce89ee9f4ca27312d29751f58fc26a24f7..5297f15a02f121db8ee1ad9fcc516d04e5c4d9a8 100644 (file)
@@ -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.
index 4bb4f21cecf22fd95bb550d86bea951733b29eeb..68b5f26ae24878666a225f991c48a37e821b5e9f 100644 (file)
@@ -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()