]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix error handling in read_until_close 1482/head
authorMartin Sucha <martin.sucha@infinario.com>
Fri, 7 Aug 2015 13:42:48 +0000 (15:42 +0200)
committerMartin Sucha <martin.sucha@infinario.com>
Mon, 10 Aug 2015 12:25:21 +0000 (14:25 +0200)
When a callback is supplied, the future is not created. Make sure
it is used only if it was initialized, otherwise we lose the
error that was originally raised.

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

index e17786ae1010fa0df6b8218bcce6ad74f9661acf..c5d3e2c9dc3418ec2817a2f8553be1cbfcf3e936 100644 (file)
@@ -352,7 +352,8 @@ class BaseIOStream(object):
         try:
             self._try_inline_read()
         except:
-            future.add_done_callback(lambda f: f.exception())
+            if future is not None:
+                future.add_done_callback(lambda f: f.exception())
             raise
         return future
 
index bc12c818967d12d06dbe1f33e26fdeda62da5dfc..060f7a454f12296518d9499c85a5e79062149e48 100644 (file)
@@ -457,6 +457,18 @@ class TestIOStreamMixin(object):
             server.close()
             client.close()
 
+    @unittest.skipIf(mock is None, 'mock package not present')
+    def test_read_until_close_with_error(self):
+        server, client = self.make_iostream_pair()
+        try:
+            with mock.patch('tornado.iostream.BaseIOStream._try_inline_read',
+                            side_effect=IOError('boom')):
+                with self.assertRaisesRegexp(IOError, 'boom'):
+                    client.read_until_close(self.stop)
+        finally:
+            server.close()
+            client.close()
+
     def test_streaming_read_until_close_after_close(self):
         # Same as the preceding test but with a streaming_callback.
         # All data should go through the streaming callback,