mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
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:
parent
230b2ba4ef
commit
12ec996d54
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user