From e77d47cb9797d3603f1b32ae864a96a7d24f7d3a Mon Sep 17 00:00:00 2001 From: benoitc Date: Wed, 5 Jun 2013 10:41:56 +0200 Subject: [PATCH] don't raise an error when we close the socket. fix #537 --- gunicorn/workers/async.py | 8 ++++++-- gunicorn/workers/sync.py | 9 +++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index c1da8649..a62dec6a 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -108,8 +108,12 @@ class AsyncWorker(base.Worker): 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() + try: + sock.shutdown(socket.SHUT_RDWR) + sock.close() + except socket.error: + pass + return raise finally: try: diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index e2ea712f..baf45a90 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -142,8 +142,13 @@ class SyncWorker(base.Worker): 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() + try: + client.shutdown(socket.SHUT_RDWR) + client.close() + except socket.error: + pass + + return # Only send back traceback in HTTP in debug mode. self.handle_error(req, client, addr, e) return