From: Ben Darnell Date: Wed, 1 May 2013 03:37:37 +0000 (-0400) Subject: Add an exception handler in _try_inline_read to ensure close_callback is run. X-Git-Tag: v3.1.0~88 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5cb854263f6e3e22b9d7109ccf704357a15d65ce;p=thirdparty%2Ftornado.git Add an exception handler in _try_inline_read to ensure close_callback is run. This is probably just a stopgap until some larger refactoring around pending_callbacks, but will help with the max_buffer_size leak. --- diff --git a/tornado/iostream.py b/tornado/iostream.py index 5b4a45f9c..ad395f0e2 100644 --- a/tornado/iostream.py +++ b/tornado/iostream.py @@ -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()