Skip to content

Commit 4b346bd

Browse files
committed
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
1 parent 8572cc4 commit 4b346bd

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

tornado/httpserver.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,14 @@ def _on_write_complete(self):
190190
callback = self._write_callback
191191
self._write_callback = None
192192
callback()
193-
if self._request_finished:
193+
# _on_write_complete is enqueued on the IOLoop whenever the
194+
# IOStream's write buffer becomes empty, but it's possible for
195+
# another callback that runs on the IOLoop before it to
196+
# simultaneously write more data and finish the request. If
197+
# there is still data in the IOStream, a future
198+
# _on_write_complete will be responsible for calling
199+
# _finish_request.
200+
if self._request_finished and not self.stream.writing():
194201
self._finish_request()
195202

196203
def _finish_request(self):

0 commit comments

Comments
 (0)