Commit ff9d2895 authored by Denis Bilenko's avatar Denis Bilenko

wsgi: fix issue #58: even if http_request instance is leaked, reply with 500...

wsgi: fix issue #58: even if http_request instance is leaked, reply with 500 error immediatelly when application raises an error. Thanks to Jon Aslund.
parent b855435a
...@@ -117,6 +117,7 @@ class WSGIHandler(object): ...@@ -117,6 +117,7 @@ class WSGIHandler(object):
if hasattr(result, 'close'): if hasattr(result, 'close'):
result.close() result.close()
except GreenletExit: except GreenletExit:
self._reply500()
raise raise
except: except:
traceback.print_exc() traceback.print_exc()
...@@ -125,14 +126,17 @@ class WSGIHandler(object): ...@@ -125,14 +126,17 @@ class WSGIHandler(object):
(self.server, self.request, self.server.application)) (self.server, self.request, self.server.application))
except Exception: except Exception:
pass pass
# do not call self.end so that core.http replies with 500 self._reply500()
self = None
return
finally: finally:
sys.exc_clear() sys.exc_clear()
if self is not None and self.code is not None: if self is not None and self.code is not None:
self.end(env) self.end(env)
def _reply500(self):
self.reason = None
self.start_response('500 Internal Server Error', [('Content-Type', 'text/plain')])
self.write('Internal Server Error')
class WSGIServer(HTTPServer): class WSGIServer(HTTPServer):
"""A fast WSGI server based on :class:`HTTPServer`.""" """A fast WSGI server based on :class:`HTTPServer`."""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment