facebook/tornado — Issue #473: Uncaught exceptions when client closes connection
Author: davidgaleano
Created: 2012-02-29 13:00:27+00:00
State: open

This issue is not always easy to reproduce but when we manage to reproduce it the client was always a Google Chrome browser, the server is just a plain http one. It seems the browser may be closing the socket without waiting for the server to reply.

This is a traceback for the server running on Mac OS X 10.7:

Traceback (most recent call last):
File "/Users/david/env/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/netutil.py", line 215, in _handle_connection
self.handle_stream(stream, address)
File "/Users/david/env/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/httpserver.py", line 144, in handle_stream
self.no_keep_alive, self.xheaders)
File "/Users/david/env/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/httpserver.py", line 171, in init
self.stream.read_until(b("\r\n\r\n"), self._header_callback)
File "/Users/david/env/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/iostream.py", line 161, in read_until
if self._read_to_buffer() == 0:
File "/Users/david/env/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/iostream.py", line 375, in _read_to_buffer
chunk = self._read_from_socket()
File "/Users/david/env/lib/python2.7/site-packages/tornado-2.1.1-py2.7.egg/tornado/iostream.py", line 356, in _read_from_socket
chunk = self.socket.recv(self.read_chunk_size)
error: [Errno 54] Connection reset by peer

These are other tracebacks for a server running on Windows 7 64bit:

Traceback (most recent call last):
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 983, in _execute
self.prepare()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 1628, in prepare
self.fallback(self.request)
File "C:\Devlp\turbulenz\devserver\paste_factory.py", line 51, in __call__
request.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 422, in finish
self.connection.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 186, in finish
self._finish_request()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 222, in _finish_request
self.stream.read_until(b("\r\n\r\n"), self._header_callback)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\iostream.py", line 160, in read_until
self._check_closed()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\iostream.py", line 535, in _check_closed
raise IOError("Stream is closed")
IOError: Stream is closed

Traceback (most recent call last):
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 693, in send_error
self.write_error(status_code, **kwargs)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 739, in write_error
"message": httplib.responses[status_code],
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 668, in finish
self.flush(include_footers=True)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 631, in flush
self.request.write(headers + chunk, callback=callback)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 418, in write
self.connection.write(chunk, callback=callback)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 176, in write
assert self._request, "Request closed"
AssertionError: Request closed

Traceback (most recent call last):
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\iostream.py", line 304, in wrapper
callback(*args)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 280, in _on_request_body
self.request_callback(self._request)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 1362, in __call__
handler._execute(transforms, *args, **kwargs)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 992, in _execute
self._handle_request_exception(e)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 1032, in _handle_request_exception
self.send_error(500, exc_info=sys.exc_info())
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 697, in send_error
self.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 669, in finish
self.request.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 422, in finish
self.connection.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 183, in finish
assert self._request, "Request closed"
AssertionError: Request closed

Traceback (most recent call last):
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\ioloop.py", line 399, in _run_callback
callback()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\iostream.py", line 304, in wrapper
callback(*args)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 280, in _on_request_body
self.request_callback(self._request)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 1362, in __call__
handler._execute(transforms, *args, **kwargs)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 992, in _execute
self._handle_request_exception(e)
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 1032, in _handle_request_exception
self.send_error(500, exc_info=sys.exc_info())
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 697, in send_error
self.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\web.py", line 669, in finish
self.request.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 422, in finish
self.connection.finish()
File "C:\Devlp\env\lib\site-packages\tornado-2.2-py2.7.egg\tornado\httpserver.py", line 183, in finish
assert self._request, "Request closed"
AssertionError: Request closed