Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Delete HTTPConnection._close_callback in between requests.

Previously the close callback would cause a reference to the previous
RequestHandler to be retained while waiting for the next request.
  • Loading branch information...
commit 646f92fcdd3f932ca1393c14917ceda53e583837 1 parent e00e4c6
@bdarnell bdarnell authored
Showing with 15 additions and 1 deletion.
  1. +15 −1 tornado/
16 tornado/
@@ -182,10 +182,21 @@ def __init__(self, stream, address, request_callback, no_keep_alive=False,
self.protocol = protocol
self._request = None
self._request_finished = False
+ self._write_callback = None
+ self._close_callback = None
# Save stack context here, outside of any request. This keeps
# contexts from one request from leaking into the next.
self._header_callback = stack_context.wrap(self._on_headers)"\r\n\r\n", self._header_callback)
+ def _clear_callbacks(self):
+ """Clears the per-request callbacks.
+ This is run in between requests to allow the previous handler
+ to be garbage collected (and prevent spurious close callbacks),
+ and when the connection is closed (to break up cycles and
+ facilitate garbage collection in cpython).
+ """
self._write_callback = None
self._close_callback = None
@@ -205,13 +216,15 @@ def _on_connection_close(self):
self._close_callback = None
# Delete any unfinished callbacks to break up reference cycles.
- self._write_callback = None
+ self._header_callback = None
+ self._clear_callbacks()
def close(self):
# Remove this reference to self, which would otherwise cause a
# cycle and delay garbage collection of this connection.
self._header_callback = None
+ self._clear_callbacks()
def write(self, chunk, callback=None):
"""Writes a chunk of output to the stream."""
@@ -258,6 +271,7 @@ def _finish_request(self):
disconnect = True
self._request = None
self._request_finished = False
+ self._clear_callbacks()
if disconnect:
Please sign in to comment.
Something went wrong with that request. Please try again.