IOError "Stream is closed" not caught in finish() #81

Closed
parente opened this Issue Apr 1, 2010 · 4 comments

4 participants

@parente

Is it expected that my handler should catch this exception? When it happens, the server goes into limbo and no longer handles requests.

...
self.finish()
File "/home/parente/envs/jsonic/lib/python2.6/site-packages/tornado-0.2-py2.6.egg/tornado/web.py", line 459, in finish
self.flush(include_footers=True)
File "/home/parente/envs/jsonic/lib/python2.6/site-packages/tornado-0.2-py2.6.egg/tornado/web.py", line 433, in flush
self.request.write(headers + chunk)
File "/home/parente/envs/jsonic/lib/python2.6/site-packages/tornado-0.2-py2.6.egg/tornado/httpserver.py", line 286, in write
self.connection.write(chunk)
File "/home/parente/envs/jsonic/lib/python2.6/site-packages/tornado-0.2-py2.6.egg/tornado/httpserver.py", line 126, in write
self.stream.write(chunk, self._on_write_complete)
File "/home/parente/envs/jsonic/lib/python2.6/site-packages/tornado-0.2-py2.6.egg/tornado/iostream.py", line 111, in write
self._check_closed()
File "/home/parente/envs/jsonic/lib/python2.6/site-packages/tornado-0.2-py2.6.egg/tornado/iostream.py", line 223, in _check_closed
raise IOError("Stream is closed")
IOError: Stream is closed

@bdarnell
tornadoweb member

This should no longer throw an exception.

@jparise

Since upgrading to Tornado 2.4, I've seen these exceptions start to bubble up once again. I'm working around them in a RequestHandler subclass:

    def finish(self, chunk=None):
        if not self.request.connection.stream.closed():
            super(RequestHandler, self).finish(chunk)

... but that's not ideal.

@bdarnell
tornadoweb member

@jparise can you post a stack trace? (or open a new issue, since I think the exception is coming from a different place than in this two-year-old bug)

@zhyq0826

I have encounted the same problem when the client connection closed before the sever write.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment