# Buggy code
def handle(self, listener, client, addr):
    req = None
    try:
        if self.cfg.is_ssl:
            client = ssl.wrap_socket(client, server_side=True, **self.cfg.ssl_options)

        parser = http.RequestParser(self.cfg, client)
        req = six.next(parser)
        self.handle_request(listener, req, client, addr)
    except http.errors.NoMoreData as e:
        self.log.debug("Ignored premature client disconnection. %s", e)
    except StopIteration as e:
        self.log.debug("Closing connection. %s", e)
    except ssl.SSLError as e:
        if e.args[0] == ssl.SSL_ERROR_EOF:
            self.log.debug("ssl connection closed")
            client.close()
        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):
            self.log.exception("Socket error processing request.")
        else:
            if e.args[0] == errno.ECONNRESET:
                self.log.debug("Ignoring connection reset")
            else:
                self.log.debug("Ignoring EPIPE")
    except Exception as e:
        self.handle_error(req, client, addr, e)
    finally:
        util.close(client)


# Traceback (BrokenPipeError)
[2014-11-17 04:18:49 -0500] [13520] [ERROR] Error handling request
Traceback (most recent call last):
File "/usr/local/lib/python3.4/site-packages/gunicorn/workers/async.py", line 108, in handle_request
resp.write(item)
File "/usr/local/lib/python3.4/site-packages/gunicorn/http/wsgi.py", line 344, in write
util.write(self.sock, arg, self.chunked)
File "/usr/local/lib/python3.4/site-packages/gunicorn/util.py", line 301, in write
sock.sendall(data)
File "/usr/local/lib/python3.4/site-packages/eventlet/greenio.py", line 375, in sendall
tail = self.send(data, flags)
File "/usr/local/lib/python3.4/site-packages/eventlet/greenio.py", line 358, in send
total_sent += fd.send(data[total_sent:], flags)
File "/usr/local/lib/python3.4/site-packages/eventlet/greenio.py", line 351, in send
return fd.send(data, flags)
BrokenPipeError: [Errno 32] Broken pipe

# Fixed code
def handle(self, listener, client, addr):
    req = None
    try:
        if self.cfg.is_ssl:
            client = ssl.wrap_socket(client, server_side=True, **self.cfg.ssl_options)

        parser = http.RequestParser(self.cfg, client)
        req = six.next(parser)
        self.handle_request(listener, req, client, addr)
    except http.errors.NoMoreData as e:
        self.log.debug("Ignored premature client disconnection. %s", e)
    except StopIteration as e:
        self.log.debug("Closing connection. %s", e)
    except ssl.SSLError as e:
        if e.args[0] == ssl.SSL_ERROR_EOF:
            self.log.debug("ssl connection closed")
            client.close()
        else:
            self.log.debug("Error processing SSL request.")
            self.handle_error(req, client, addr, e)
    except EnvironmentError as e:
        if e.errno not in (errno.EPIPE, errno.ECONNRESET):
            self.log.exception("Socket error processing request.")
        else:
            if e.errno == errno.ECONNRESET:
                self.log.debug("Ignoring connection reset")
            else:
                self.log.debug("Ignoring EPIPE")
    except Exception as e:
        self.handle_error(req, client, addr, e)
    finally:
        util.close(client)