Esempio n. 1
0
def ignore_aiohttp_ssl_error(loop):
    """Ignore aiohttp #3535 / cpython #13548 issue with SSL data after close

    There is an issue in Python 3.7 up to 3.7.3 that over-reports a
    ssl.SSLError fatal error (ssl.SSLError: [SSL: KRB5_S_INIT] application data
    after close notify (_ssl.c:2609)) after we are already done with the
    connection. See GitHub issues aio-libs/aiohttp#3535 and
    python/cpython#13548.

    Given a loop, this sets up an exception handler that ignores this specific
    exception, but passes everything else on to the previous exception handler
    this one replaces.
    """

    orig_handler = loop.get_exception_handler()

    def ignore_ssl_error(loop2, context):
        if context.get("message") in {
                "SSL error in data received",
                "Fatal error on transport",
        }:
            # validate we have the right exception, transport and protocol
            exception = context.get("exception")
            protocol = context.get("protocol")
            if (isinstance(exception, ssl.SSLError)
                    and exception.reason == "KRB5_S_INIT"
                    and isinstance(protocol, SSL_PROTOCOLS)):
                return
        if orig_handler is not None:
            orig_handler(loop2, context)
        else:
            loop.default_exception_handler(context)

    loop.set_exception_handler(ignore_ssl_error)
Esempio n. 2
0
def ignore_aiohttp_ssl_eror(loop):
    """Ignore aiohttp #3535 / cpython #13548 issue with SSL data after close

	There is an issue in Python 3.7 up to 3.7.3 that over-reports a
	ssl.SSLError fatal error (ssl.SSLError: [SSL: KRB5_S_INIT] application data
	after close notify (_ssl.c:2609)) after we are already done with the
	connection. See GitHub issues aio-libs/aiohttp#3535 and
	python/cpython#13548.

	Given a loop, this sets up an exception handler that ignores this specific
	exception, but passes everything else on to the previous exception handler
	this one replaces.

	Checks for fixed Python versions, disabling itself when running on 3.7.4+
	or 3.8.

	"""
    # if sys.version_info >= (3, 7, 4):
    # 	return

    orig_handler = loop.get_exception_handler()

    def ignore_ssl_error(loop, context):
        SSL_PROTOCOLS = (asyncio.sslproto.SSLProtocol, )
        try:
            import uvloop.loop
        except ImportError:
            pass
        else:
            SSL_PROTOCOLS = (*SSL_PROTOCOLS, uvloop.loop.SSLProtocol)
        if context.get("message") in {
                "SSL error in data received",
                "Fatal error on transport",
                "SSL handshake failed",
        }:
            # validate we have the right exception, transport and protocol
            exception = context.get('exception')
            protocol = context.get('protocol')
            if (isinstance(exception, ssl.SSLError)
                    and exception.reason == 'KRB5_S_INIT'
                    and isinstance(protocol, SSL_PROTOCOLS)):
                if loop.get_debug():
                    asyncio.log.logger.debug(
                        'Ignoring asyncio SSL KRB5_S_INIT error')
                return
        if orig_handler is not None:
            orig_handler(loop, context)
        else:
            loop.default_exception_handler(context)

    loop.set_exception_handler(ignore_ssl_error)