From bb7410c3634cdb872194e51b3029c8169373b9c7 Mon Sep 17 00:00:00 2001 From: Ryan Williams Date: Sun, 10 Jan 2010 12:08:49 -0800 Subject: [PATCH] Cleaned up error catching in wsgi a little bit, being careful-er about what's in the socket.error that's being raised. --- eventlet/wsgi.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/eventlet/wsgi.py b/eventlet/wsgi.py index e7907f7..a158b20 100644 --- a/eventlet/wsgi.py +++ b/eventlet/wsgi.py @@ -29,6 +29,11 @@ def format_date_time(timestamp): _weekdayname[wd], day, _monthname[month], year, hh, mm, ss ) +# Collections of error codes to compare against. Not all attributes are set +# on errno module on all platforms, so some are literals :( +BAD_SOCK = set((errno.EBADF, 10053)) +BROKEN_SOCK = set((errno.EPIPE, errno.ECONNRESET)) + class Input(object): def __init__(self, rfile, @@ -154,7 +159,7 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler): except greenio.SSL.ZeroReturnError: self.raw_requestline = '' except socket.error, e: - if e[0] != errno.EBADF and e[0] != 10053: + if getattr(e, 'errno', 0) not in BAD_SOCK: raise self.raw_requestline = '' @@ -184,9 +189,7 @@ class HttpProtocol(BaseHTTPServer.BaseHTTPRequestHandler): self.handle_one_response() except socket.error, e: # Broken pipe, connection reset by peer - if e[0] in (32, 54): - pass - else: + if getattr(e, 'errno', 0) not in BROKEN_SOCK: raise finally: self.server.outstanding_requests -= 1 @@ -474,7 +477,7 @@ def server(sock, site, try: client_socket = sock.accept() except socket.error, e: - if e[0] != errno.EPIPE and e[0] != errno.EBADF: + if getattr(e, 'errno', 0) not in BAD_SOCK + BROKEN_SOCK: raise pool.execute_async(serv.process_request, client_socket) except (KeyboardInterrupt, SystemExit): @@ -485,6 +488,6 @@ def server(sock, site, greenio.shutdown_safe(sock) sock.close() except socket.error, e: - if e[0] != errno.EPIPE: + if getattr(e, 'errno', 0) not in BROKEN_SOCK: traceback.print_exc()