Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

When closing an HTTPConnection, also clear a circular reference to self.

This reference could cause garbage collection of the connection object
to be delayed.

Closes #586.
  • Loading branch information...
commit 0e6540bfd266cea513d159a11772c90ffbf6945b 1 parent 302c503
@bdarnell bdarnell authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 tornado/httpserver.py
View
10 tornado/httpserver.py
@@ -172,6 +172,12 @@ def __init__(self, stream, address, request_callback, no_keep_alive=False,
self.stream.read_until(b("\r\n\r\n"), self._header_callback)
self._write_callback = None
+ def close(self):
+ self.stream.close()
+ # Remove this reference to self, which would otherwise cause a
+ # cycle and delay garbage collection of this connection.
+ self._header_callback = None
+
def write(self, chunk, callback=None):
"""Writes a chunk of output to the stream."""
assert self._request, "Request closed"
@@ -218,7 +224,7 @@ def _finish_request(self):
self._request = None
self._request_finished = False
if disconnect:
- self.stream.close()
+ self.close()
return
self.stream.read_until(b("\r\n\r\n"), self._header_callback)
@@ -263,7 +269,7 @@ def _on_headers(self, data):
except _BadRequestException, e:
logging.info("Malformed HTTP request from %s: %s",
self.address[0], e)
- self.stream.close()
+ self.close()
return
def _on_request_body(self, data):
Please sign in to comment.
Something went wrong with that request. Please try again.