diff --git a/gunicorn/workers/async.py b/gunicorn/workers/async.py index a62dec6a..3bf963c0 100644 --- a/gunicorn/workers/async.py +++ b/gunicorn/workers/async.py @@ -105,7 +105,7 @@ class AsyncWorker(base.Worker): if resp.should_close(): raise StopIteration() except Exception: - if resp.headers_sent: + if resp and resp.headers_sent: # If the requests have already been sent, we should close the # connection to indicate the error. try: diff --git a/gunicorn/workers/sync.py b/gunicorn/workers/sync.py index 12dfacd5..347b6a28 100644 --- a/gunicorn/workers/sync.py +++ b/gunicorn/workers/sync.py @@ -144,7 +144,7 @@ class SyncWorker(base.Worker): except socket.error: raise except Exception as e: - if resp.headers_sent: + if resp and resp.headers_sent: # If the requests have already been sent, we should close the # connection to indicate the error. try: