mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
prevent crash when reporting an error
Try to not crash when reporting an error. This changes makes sure we can log the uri and also handle SSL errors. fix #1177
This commit is contained in:
parent
6b34cdba71
commit
1ccebab763
@ -5,12 +5,12 @@
|
|||||||
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import os
|
import os
|
||||||
|
from random import randint
|
||||||
import signal
|
import signal
|
||||||
|
from ssl import SSLError
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from random import randint
|
|
||||||
|
|
||||||
|
|
||||||
from gunicorn import util
|
from gunicorn import util
|
||||||
from gunicorn.workers.workertmp import WorkerTmp
|
from gunicorn.workers.workertmp import WorkerTmp
|
||||||
@ -181,7 +181,8 @@ class Worker(object):
|
|||||||
if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,
|
if isinstance(exc, (InvalidRequestLine, InvalidRequestMethod,
|
||||||
InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,
|
InvalidHTTPVersion, InvalidHeader, InvalidHeaderName,
|
||||||
LimitRequestLine, LimitRequestHeaders,
|
LimitRequestLine, LimitRequestHeaders,
|
||||||
InvalidProxyLine, ForbiddenProxyRequest)):
|
InvalidProxyLine, ForbiddenProxyRequest,
|
||||||
|
SSLError)):
|
||||||
|
|
||||||
status_int = 400
|
status_int = 400
|
||||||
reason = "Bad Request"
|
reason = "Bad Request"
|
||||||
@ -206,12 +207,16 @@ class Worker(object):
|
|||||||
reason = "Forbidden"
|
reason = "Forbidden"
|
||||||
mesg = "Request forbidden"
|
mesg = "Request forbidden"
|
||||||
status_int = 403
|
status_int = 403
|
||||||
|
elif isinstance(exc, SSLError):
|
||||||
|
reason = "Forbidden"
|
||||||
|
mesg = "'%s'" % str(exc)
|
||||||
|
status_int = 403
|
||||||
|
|
||||||
msg = "Invalid request from ip={ip}: {error}"
|
msg = "Invalid request from ip={ip}: {error}"
|
||||||
self.log.debug(msg.format(ip=addr[0], error=str(exc)))
|
self.log.debug(msg.format(ip=addr[0], error=str(exc)))
|
||||||
else:
|
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
|
status_int = 500
|
||||||
reason = "Internal Server Error"
|
reason = "Internal Server Error"
|
||||||
mesg = ""
|
mesg = ""
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user