From: Kefu Chai Date: Sun, 27 Oct 2019 03:10:22 +0000 (+0800) Subject: mgr/dashboard: accept socket error 0 X-Git-Tag: v14.2.8~99^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=56fd8b67449d6d0855cf15ee81d6577949d12c9d;p=ceph.git mgr/dashboard: accept socket error 0 see https://github.com/cherrypy/cheroot/commit/9d73226ab28a07a38cbb6816edf9ff46be4f9de3 Fixes: https://tracker.ceph.com/issues/38378 Signed-off-by: Kefu Chai (cherry picked from commit 482561bd5504fe539621305504a25542bf44e6b2) Signed-off-by: Ernesto Puerta --- diff --git a/src/pybind/mgr/dashboard/cherrypy_backports.py b/src/pybind/mgr/dashboard/cherrypy_backports.py index 83c15e1464e..db994b9a7f3 100644 --- a/src/pybind/mgr/dashboard/cherrypy_backports.py +++ b/src/pybind/mgr/dashboard/cherrypy_backports.py @@ -77,7 +77,49 @@ def accept_exceptions_from_builtin_ssl(v): patch_builtin_ssl_wrap(v, accept_ssl_errors) +def accept_socket_error_0(v): + # see https://github.com/cherrypy/cherrypy/issues/1618 + try: + import cheroot + cheroot_version = cheroot.__version__ + except ImportError: + pass + + if v < StrictVersion("9.0.0") or cheroot_version < StrictVersion("6.5.5"): + import six + if six.PY3: + generic_socket_error = OSError + else: + import socket + generic_socket_error = socket.error + + def accept_socket_error_0(func): + def wrapper(self, sock): + try: + return func(self, sock) + except generic_socket_error as e: + """It is unclear why exactly this happens. + + It's reproducible only with openssl>1.0 and stdlib ``ssl`` wrapper. + In CherryPy it's triggered by Checker plugin, which connects + to the app listening to the socket port in TLS mode via plain + HTTP during startup (from the same process). + + Ref: https://github.com/cherrypy/cherrypy/issues/1618 + """ + import ssl + is_error0 = e.args == (0, 'Error') + IS_ABOVE_OPENSSL10 = ssl.OPENSSL_VERSION_INFO >= (1, 1) + del ssl + if is_error0 and IS_ABOVE_OPENSSL10: + return None, {} + raise + return wrapper + patch_builtin_ssl_wrap(v, accept_socket_error_0) + + def patch_cherrypy(v): patch_http_connection_init(v) skip_wait_for_occupied_port(v) accept_exceptions_from_builtin_ssl(v) + accept_socket_error_0(v)