]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Fix a case in which chunked responses could be closed prematurely.
authorBen Darnell <ben@bendarnell.com>
Thu, 22 Sep 2011 17:38:35 +0000 (10:38 -0700)
committerBen Darnell <ben@bendarnell.com>
Thu, 22 Sep 2011 17:38:35 +0000 (10:38 -0700)
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

index 2bdc2c6e6b6e2029fdd54f12c6adc7e46faf9dd4..74f1a8acf342bc5acc6a29ad6b912d8a82ca1885 100644 (file)
@@ -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):