Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use EnvironmentError instead of socket.error (closes #939) #1197

Merged
merged 1 commit into from Feb 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 6 additions & 6 deletions gunicorn/workers/async.py
Expand Up @@ -58,7 +58,7 @@ def handle(self, listener, client, addr):
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
except socket.error:
except EnvironmentError:
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
Expand All @@ -71,11 +71,11 @@ def handle(self, listener, client, addr):
else:
self.log.debug("Error processing SSL request.")
self.handle_error(req, client, addr, e)
except socket.error as e:
if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):
except EnvironmentError as e:
if e.errno not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
if e.args[0] == errno.ECONNRESET:
if e.errno == errno.ECONNRESET:
self.log.debug("Ignoring connection reset")
else:
self.log.debug("Ignoring EPIPE")
Expand Down Expand Up @@ -121,7 +121,7 @@ def handle_request(self, listener_name, req, sock, addr):
raise StopIteration()
except StopIteration:
raise
except socket.error:
except EnvironmentError:
# If the original exception was a socket.error we delegate
# handling it to the caller (where handle() might ignore it)
six.reraise(*sys.exc_info())
Expand All @@ -133,7 +133,7 @@ def handle_request(self, listener_name, req, sock, addr):
try:
sock.shutdown(socket.SHUT_RDWR)
sock.close()
except socket.error:
except EnvironmentError:
pass
raise StopIteration()
raise
Expand Down
18 changes: 9 additions & 9 deletions gunicorn/workers/gthread.py
Expand Up @@ -135,8 +135,8 @@ def accept(self, listener):
self.nr_conns += 1
# enqueue the job
self.enqueue_req(conn)
except socket.error as e:
if e.args[0] not in (errno.EAGAIN,
except EnvironmentError as e:
if e.errno not in (errno.EAGAIN,
errno.ECONNABORTED, errno.EWOULDBLOCK):
raise

Expand Down Expand Up @@ -176,8 +176,8 @@ def murder_keepalived(self):
with self._lock:
try:
self.poller.unregister(conn.sock)
except socket.error as e:
if e.args[0] != errno.EBADF:
except EnvironmentError as e:
if e.errno != errno.EBADF:
raise

# close the socket
Expand Down Expand Up @@ -287,11 +287,11 @@ def handle(self, conn):
self.log.debug("Error processing SSL request.")
self.handle_error(req, conn.sock, conn.addr, e)

except socket.error as e:
if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):
except EnvironmentError as e:
if e.errno not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
if e.args[0] == errno.ECONNRESET:
if e.errno == errno.ECONNRESET:
self.log.debug("Ignoring connection reset")
else:
self.log.debug("Ignoring connection epipe")
Expand Down Expand Up @@ -338,7 +338,7 @@ def handle_request(self, req, conn):
if resp.should_close():
self.log.debug("Closing connection.")
return False
except socket.error:
except EnvironmentError:
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
Expand All @@ -350,7 +350,7 @@ def handle_request(self, req, conn):
try:
conn.sock.shutdown(socket.SHUT_RDWR)
conn.sock.close()
except socket.error:
except EnvironmentError:
pass
raise StopIteration()
raise
Expand Down
18 changes: 9 additions & 9 deletions gunicorn/workers/sync.py
Expand Up @@ -69,8 +69,8 @@ def run_for_one(self, timeout):
# process.
continue

except socket.error as e:
if e.args[0] not in (errno.EAGAIN, errno.ECONNABORTED,
except EnvironmentError as e:
if e.errno not in (errno.EAGAIN, errno.ECONNABORTED,
errno.EWOULDBLOCK):
raise

Expand All @@ -95,8 +95,8 @@ def run_for_multiple(self, timeout):
for listener in ready:
try:
self.accept(listener)
except socket.error as e:
if e.args[0] not in (errno.EAGAIN, errno.ECONNABORTED,
except EnvironmentError as e:
if e.errno not in (errno.EAGAIN, errno.ECONNABORTED,
errno.EWOULDBLOCK):
raise

Expand Down Expand Up @@ -139,11 +139,11 @@ def handle(self, listener, client, addr):
else:
self.log.debug("Error processing SSL request.")
self.handle_error(req, client, addr, e)
except socket.error as e:
if e.args[0] not in (errno.EPIPE, errno.ECONNRESET):
except EnvironmentError as e:
if e.errno not in (errno.EPIPE, errno.ECONNRESET):
self.log.exception("Socket error processing request.")
else:
if e.args[0] == errno.ECONNRESET:
if e.errno == errno.ECONNRESET:
self.log.debug("Ignoring connection reset")
else:
self.log.debug("Ignoring EPIPE")
Expand Down Expand Up @@ -181,7 +181,7 @@ def handle_request(self, listener, req, client, addr):
finally:
if hasattr(respiter, "close"):
respiter.close()
except socket.error:
except EnvironmentError:
exc_info = sys.exc_info()
# pass to next try-except level
six.reraise(exc_info[0], exc_info[1], exc_info[2])
Expand All @@ -193,7 +193,7 @@ def handle_request(self, listener, req, client, addr):
try:
client.shutdown(socket.SHUT_RDWR)
client.close()
except socket.error:
except EnvironmentError:
pass
raise StopIteration()
raise
Expand Down