Skip to content
Snippets Groups Projects
Commit cb8a09ed authored by jooola's avatar jooola
Browse files

fix: remove ignore_aiohttp_ssl_error workaround

Part-of: <!58>
parent 0ae4d86c
No related branches found
No related tags found
1 merge request!58test: add flake linter
import asyncio
import functools
import ssl
import sys
import aiohttp
......@@ -12,67 +11,10 @@ from funkwhale_network.worker import WorkerSettings
from . import output
SSL_PROTOCOLS = (asyncio.sslproto.SSLProtocol,)
try:
import uvloop.loop
except ImportError:
pass
else:
SSL_PROTOCOLS = (*SSL_PROTOCOLS, uvloop.loop.SSLProtocol)
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):
if context.get("message") in {
"SSL error in data received",
"Fatal error on transport",
"SSL handshake failed",
"[SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error",
}:
# 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 in ("KRB5_S_INIT", "TLSV1_ALERT_INTERNAL_ERROR")
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)
def async_command(f):
def wrapper(*args, **kwargs):
loop = asyncio.get_event_loop()
ignore_aiohttp_ssl_eror(loop)
return loop.run_until_complete(f(*args, **kwargs))
return functools.update_wrapper(wrapper, f)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment