'Stream is closed' crashing the tornado process

888 views
Skip to first unread message

Nick Jennings

unread,
Jul 19, 2012, 8:55:00 AM7/19/12
to python-...@googlegroups.com
Hi All,

I've got a strange problem that I can't quite put my finger on, was
wondering if anyone had any experience with this.

I've got a flash front-end, using websocets. It seems like once in a
while, the flash app looses connection and tries to reconnect, this is
what happens on the server:

(the printed message 'unregistered client' is printed when the
'on_close()' method is called)

unregistered client
ListenHandler __init__
ERROR:root:Uncaught exception, closing connection.
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py",
line 304, in wrapper
callback(*args)
File "/usr/local/lib/python2.7/dist-packages/tornado/httpserver.py",
line 262, in _on_headers
self.request_callback(self._request)
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line
1412, in __call__
handler._execute(transforms, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tornado/websocket.py",
line 123, in _execute
self.ws_connection.accept_connection()
File "/usr/local/lib/python2.7/dist-packages/tornado/websocket.py",
line 458, in accept_connection
self._accept_connection()
File "/usr/local/lib/python2.7/dist-packages/tornado/websocket.py",
line 497, in _accept_connection
"\r\n" % (self._challenge_response(), subprotocol_header)))
File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py",
line 196, in write
self._check_closed()
File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py",
line 564, in _check_closed
raise IOError("Stream is closed")
IOError: Stream is closed
ERROR:root:Exception in callback
<tornado.stack_context._StackContextWrapper object at 0x7ffd3c12c6d8>
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tornado/ioloop.py",
line 421, in _run_callback
callback()
File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py",
line 304, in wrapper
callback(*args)
File "/usr/local/lib/python2.7/dist-packages/tornado/httpserver.py",
line 262, in _on_headers
self.request_callback(self._request)
File "/usr/local/lib/python2.7/dist-packages/tornado/web.py", line
1412, in __call__
handler._execute(transforms, *args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/tornado/websocket.py",
line 123, in _execute
self.ws_connection.accept_connection()
File "/usr/local/lib/python2.7/dist-packages/tornado/websocket.py",
line 458, in accept_connection
self._accept_connection()
File "/usr/local/lib/python2.7/dist-packages/tornado/websocket.py",
line 497, in _accept_connection
"\r\n" % (self._challenge_response(), subprotocol_header)))
File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py",
line 196, in write
self._check_closed()
File "/usr/local/lib/python2.7/dist-packages/tornado/iostream.py",
line 564, in _check_closed
raise IOError("Stream is closed")
IOError: Stream is closed


It seems like the flash client is disconnection (on_close()) but then
immediately trying to communicate on the same stream? Is this
possible? How can I gracefully handle these situations so it doesn't
bring down the socket server?

Thanks for any help!
-Nick

Serge S. Koval

unread,
Jul 19, 2012, 10:44:45 AM7/19/12
to python-...@googlegroups.com
I saw this issue before and, basically, suppressing it in sockjs-tornado/tornadio2.

Websocket require additional close handshake to be sent when closing connection. If connection drops, tornado will still try to send close handshake over closed socket, which will rethrow the exception.
I don't recall all details now, but something along these lines.

Serge.

Nick Jennings

unread,
Jul 19, 2012, 11:13:33 AM7/19/12
to python-...@googlegroups.com
Hi Serge, thanks for your response. Though how do I go about
supressing it? I'm new to tornado and not sure what you meant there.

Nick Jennings

unread,
Aug 12, 2012, 6:04:41 PM8/12/12
to python-...@googlegroups.com
Hi All,

I'm still having these IOError exceptions "Stream is closed" and not
sure what I can do to either prevent it, or handle the exception
gracefully. At the moment, once I get this error the socket thread is
useless. Also, maybe someone also has any suggestions as to how I can
detect that a thread is dead, so I can restart it?

Thanks for any help!
-Nick

Reply all
Reply to author
Forward
0 new messages