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