From c22bc857b0cac7305ff39d3dbf0675615273ad5c Mon Sep 17 00:00:00 2001 From: Ozzieisaacs Date: Sun, 27 Sep 2020 13:00:07 +0200 Subject: [PATCH] Fix #1629 (Gevent Tracebacks with SSL encryption) --- cps/server.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/cps/server.py b/cps/server.py index a9539964..d5e88587 100644 --- a/cps/server.py +++ b/cps/server.py @@ -27,6 +27,8 @@ try: from gevent.pywsgi import WSGIServer from gevent.pool import Pool from gevent import __version__ as _version + from greenlet import GreenletExit + import ssl VERSION = 'Gevent ' + _version _GEVENT = True except ImportError: @@ -143,6 +145,16 @@ class WebServer(object): output = _readable_listen_address(self.listen_address, self.listen_port) log.info('Starting Gevent server on %s', output) self.wsgiserver = WSGIServer(sock, self.app, log=self.access_logger, spawn=Pool(), **ssl_args) + if ssl_args: + wrap_socket = self.wsgiserver.wrap_socket + def my_wrap_socket(*args, **kwargs): + try: + return wrap_socket(*args, **kwargs) + except (ssl.SSLError) as ex: + log.warning('Gevent SSL Error: %s', ex) + raise GreenletExit + + self.wsgiserver.wrap_socket = my_wrap_socket self.wsgiserver.serve_forever() finally: if self.unix_socket_file: