From: Ben Darnell Date: Sun, 23 Feb 2014 20:30:47 +0000 (-0500) Subject: Fix close_callback handling when the Future read interface is used. X-Git-Tag: v4.0.0b1~91^2~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e22cd67dc86ab0f3bce9af401c94dca63dcac9af;p=thirdparty%2Ftornado.git Fix close_callback handling when the Future read interface is used. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index faf657a4c..113ee094d 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -449,6 +449,10 @@ class BaseIOStream(object): callback = self._read_callback self._read_callback = None self._run_callback(callback, data) + else: + # If we scheduled a callback, we will add the error listener + # afterwards. If we didn't, we have to do it now. + self._maybe_add_error_listener() def _try_inline_read(self): """Attempt to complete the current read operation from buffered data. diff --git a/tornado/test/iostream_test.py b/tornado/test/iostream_test.py index 35a4bd857..24b37b81c 100644 --- a/tornado/test/iostream_test.py +++ b/tornado/test/iostream_test.py @@ -511,6 +511,28 @@ class TestIOStreamMixin(object): server.close() client.close() + def test_future_close_callback(self): + # Regression test for interaction between the Future read interfaces + # and IOStream._maybe_add_error_listener. + server, client = self.make_iostream_pair() + closed = [False] + def close_callback(): + closed[0] = True + self.stop() + server.set_close_callback(close_callback) + try: + client.write(b'a') + future = server.read_bytes(1) + self.io_loop.add_future(future, self.stop) + self.assertEqual(self.wait().result(), b'a') + self.assertFalse(closed[0]) + client.close() + self.wait() + self.assertTrue(closed[0]) + finally: + server.close() + client.close() + class TestIOStreamWebHTTP(TestIOStreamWebMixin, AsyncHTTPTestCase): def _make_client_iostream(self):