From b95540700376ba824b61c9c8d769b16d7d7eee00 Mon Sep 17 00:00:00 2001 From: Randall Leeds Date: Mon, 7 Nov 2011 14:56:59 -0800 Subject: [PATCH] better logging on http parse errors NoMoreData now inherits StopIteration and the StopIteration clause in the workers logs the reason at debug level. --- gunicorn/http/errors.py | 2 +- gunicorn/workers/async.py | 4 ++-- gunicorn/workers/sync.py | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/gunicorn/http/errors.py b/gunicorn/http/errors.py index dd9a602b..beafa05c 100644 --- a/gunicorn/http/errors.py +++ b/gunicorn/http/errors.py @@ -6,7 +6,7 @@ class ParseException(Exception): pass -class NoMoreData(ParseException): +class NoMoreData(ParseException, StopIteration): def __init__(self, buf=None): self.buf = buf def __str__(self): diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index b1898e99..6f31e314 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -36,8 +36,8 @@ class AsyncWorker(base.Worker): if not req: break self.handle_request(req, client, addr) - except StopIteration: - pass + except StopIteration, e: + self.log.debug("Closing connection. %s", e) except socket.error, e: if e[0] not in (errno.EPIPE, errno.ECONNRESET): self.log.exception("Socket error processing request.") diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index b89830ca..d619c365 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -69,8 +69,8 @@ class SyncWorker(base.Worker): parser = http.RequestParser(client) req = parser.next() self.handle_request(req, client, addr) - except StopIteration: - self.log.debug("Ignored premature client disconnection.") + except StopIteration, e: + self.log.debug("Closing connection. %s", e) except socket.error, e: if e[0] != errno.EPIPE: self.log.exception("Error processing request.")