Skip to content

Commit

Permalink
Merge pull request #1197 from kaniini/fix-939
Browse files Browse the repository at this point in the history
use EnvironmentError instead of socket.error (closes #939)
  • Loading branch information
berkerpeksag committed Feb 2, 2016
2 parents db52b6e + 448bb0a commit 012d958
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
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

0 comments on commit 012d958

Please sign in to comment.