From 4b346bdde80c1e677ca0e235e04654f8d64b365c Mon Sep 17 00:00:00 2001 From: Ben Darnell Date: Thu, 22 Sep 2011 10:38:35 -0700 Subject: [PATCH] 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 --- tornado/httpserver.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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): -- 2.47.2