Close connection on error after sending started.

When the application starts yielding a body and then raises an error,
we should immediately close the connection to the client to indicate
the error.
This commit is contained in:
Alexandre Zani 2013-02-28 23:43:23 -08:00 committed by benoitc
parent 230b2ba4ef
commit 12ec996d54
2 changed files with 12 additions and 0 deletions

View File

@ -104,6 +104,13 @@ class AsyncWorker(base.Worker):
respiter.close()
if resp.should_close():
raise StopIteration()
except Exception:
if resp.headers_sent:
# If the requests have already been sent, we should close the
# connection to indicate the error.
sock.shutdown(socket.SHUT_RDWR)
sock.close()
raise
finally:
try:
self.cfg.post_request(self, req, environ, resp)

View File

@ -138,6 +138,11 @@ class SyncWorker(base.Worker):
except socket.error:
raise
except Exception as e:
if resp.headers_sent:
# If the requests have already been sent, we should close the
# connection to indicate the error.
client.shutdown(socket.SHUT_RDWR)
client.close()
# Only send back traceback in HTTP in debug mode.
self.handle_error(req, client, addr, e)
return