Skip to content

Commit

Permalink
prevent crash when reporting an error
Browse files Browse the repository at this point in the history
Try to not crash when reporting an error. This changes makes sure we can log the uri and also handle SSL errors.

fix #1177
  • Loading branch information
benoitc committed Mar 22, 2016
1 parent 6b34cdb commit 1ccebab
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions gunicorn/workers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

from datetime import datetime
import os
from random import randint
import signal
from ssl import SSLError
import sys
import time
import traceback
from random import randint


from gunicorn import util
from gunicorn.workers.workertmp import WorkerTmp
Expand Down Expand Up @@ -181,7 +181,8 @@ def handle_error(self, req, client, addr, exc):
if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,
InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,
LimitRequestLine, LimitRequestHeaders,
InvalidProxyLine, ForbiddenProxyRequest)):
InvalidProxyLine, ForbiddenProxyRequest,
SSLError)):

status_int = 400
reason = "Bad Request"
Expand All @@ -206,12 +207,16 @@ def handle_error(self, req, client, addr, exc):
reason = "Forbidden"
mesg = "Request forbidden"
status_int = 403
elif isinstance(exc, SSLError):
reason = "Forbidden"
mesg = "'%s'" % str(exc)
status_int = 403

msg = "Invalid request from ip={ip}: {error}"
self.log.debug(msg.format(ip=addr[0], error=str(exc)))
else:
self.log.exception("Error handling request %s", req.uri)

if hasattr(req, "uri"):
self.log.exception("Error handling request %s", req.uri)
status_int = 500
reason = "Internal Server Error"
mesg = ""
Expand Down

0 comments on commit 1ccebab

Please sign in to comment.