From b981014acc7c5c17a48df6e0ac6303b36d5df05a Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Thu, 6 Feb 2014 19:31:22 -0800 Subject: [PATCH 1/2] Log exceptions that occur after response start Fix #694 --- gunicorn/workers/async.py | 1 + gunicorn/workers/sync.py | 1 + 2 files changed, 2 insertions(+) diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index e08ebf4c..ca59d2a4 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -112,6 +112,7 @@ class AsyncWorker(base.Worker): if resp and resp.headers_sent: # If the requests have already been sent, we should close the # connection to indicate the error. + self.log.exception("Error handling request") try: sock.shutdown(socket.SHUT_RDWR) sock.close() diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index 36cdf98e..39ce7262 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -146,6 +146,7 @@ class SyncWorker(base.Worker): if resp and resp.headers_sent: # If the requests have already been sent, we should close the # connection to indicate the error. + self.log.exception("Error handling request") try: client.shutdown(socket.SHUT_RDWR) client.close() From 88ccfdb981b181087b442fc25877489c019a0679 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Thu, 6 Feb 2014 19:32:10 -0800 Subject: [PATCH 2/2] Clean up some inconsistent in error handling It is more DRY to let the exception here bubble. --- gunicorn/workers/sync.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index 39ce7262..9a3ba90b 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -102,10 +102,13 @@ class SyncWorker(base.Worker): self.log.debug("Error processing SSL request.") self.handle_error(req, client, addr, e) except socket.error as e: - if e.args[0] != errno.EPIPE: - self.log.exception("Error processing request.") + if e.args[0] not in (errno.EPIPE, errno.ECONNRESET): + self.log.exception("Socket error processing request.") else: - self.log.debug("Ignoring EPIPE") + if e.args[0] == errno.ECONNRESET: + self.log.debug("Ignoring connection reset") + else: + self.log.debug("Ignoring EPIPE") except Exception as e: self.handle_error(req, client, addr, e) finally: @@ -142,7 +145,7 @@ class SyncWorker(base.Worker): respiter.close() except socket.error: raise - except Exception as e: + except Exception: if resp and resp.headers_sent: # If the requests have already been sent, we should close the # connection to indicate the error. @@ -153,9 +156,7 @@ class SyncWorker(base.Worker): except socket.error: pass raise StopIteration() - # Only send back traceback in HTTP in debug mode. - self.handle_error(req, client, addr, e) - return + raise finally: try: self.cfg.post_request(self, req, environ, resp)