]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Add an exception handler in _try_inline_read to ensure close_callback is run.
authorBen Darnell <ben@bendarnell.com>
Wed, 1 May 2013 03:37:37 +0000 (23:37 -0400)
committerBen Darnell <ben@bendarnell.com>
Wed, 1 May 2013 03:37:37 +0000 (23:37 -0400)
This is probably just a stopgap until some larger refactoring around
pending_callbacks, but will help with the max_buffer_size leak.

tornado/iostream.py

index 5b4a45f9cd380b7d0f297f7db08e6cff839ae93a..ad395f0e2df91879cda903c5ef948708975a5326 100644 (file)
@@ -396,13 +396,21 @@ class BaseIOStream(object):
             return
         self._check_closed()
         try:
-            # See comments in _handle_read about incrementing _pending_callbacks
-            self._pending_callbacks += 1
-            while not self.closed():
-                if self._read_to_buffer() == 0:
-                    break
-        finally:
-            self._pending_callbacks -= 1
+            try:
+                # See comments in _handle_read about incrementing _pending_callbacks
+                self._pending_callbacks += 1
+                while not self.closed():
+                    if self._read_to_buffer() == 0:
+                        break
+            finally:
+                self._pending_callbacks -= 1
+        except Exception:
+            # If there was an in _read_to_buffer, we called close() already,
+            # but couldn't run the close callback because of _pending_callbacks.
+            # Before we escape from this function, run the close callback if
+            # applicable.
+            self._maybe_run_close_callback()
+            raise
         if self._read_from_buffer():
             return
         self._maybe_add_error_listener()