From: Ben Darnell Date: Thu, 22 Sep 2011 17:38:35 +0000 (-0700) Subject: Fix a case in which chunked responses could be closed prematurely. X-Git-Tag: v2.1.1~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b346bdde80c1e677ca0e235e04654f8d64b365c;p=thirdparty%2Ftornado.git Fix a case in which chunked responses could be closed prematurely. The bug manifests with certain patterns of fast-path/slow-path writes on the IOStream, so it's difficult to test (it was more likely to occur in 2.0 than in 2.1). http://groups.google.com/group/python-tornado/browse_thread/thread/7228881f7af38070 --- diff --git a/tornado/httpserver.py b/tornado/httpserver.py index 2bdc2c6e6..74f1a8acf 100644 --- a/tornado/httpserver.py +++ b/tornado/httpserver.py @@ -190,7 +190,14 @@ class HTTPConnection(object): callback = self._write_callback self._write_callback = None callback() - if self._request_finished: + # _on_write_complete is enqueued on the IOLoop whenever the + # IOStream's write buffer becomes empty, but it's possible for + # another callback that runs on the IOLoop before it to + # simultaneously write more data and finish the request. If + # there is still data in the IOStream, a future + # _on_write_complete will be responsible for calling + # _finish_request. + if self._request_finished and not self.stream.writing(): self._finish_request() def _finish_request(self):