diff --git a/authentik/root/asgi.py b/authentik/root/asgi.py index dc40287f7..f0ea34fee 100644 --- a/authentik/root/asgi.py +++ b/authentik/root/asgi.py @@ -20,11 +20,34 @@ django.setup() # pylint: disable=wrong-import-position from authentik.root import websocket # noqa # isort:skip + +class LifespanApp: + """ + temporary shim for https://github.com/django/channels/issues/1216 + needed so that hypercorn doesn't display an error. + this uses ASGI 2.0 format, not the newer 3.0 single callable + """ + + def __init__(self, scope): + self.scope = scope + + async def __call__(self, receive, send): + if self.scope["type"] == "lifespan": + while True: + message = await receive() + if message["type"] == "lifespan.startup": + await send({"type": "lifespan.startup.complete"}) + elif message["type"] == "lifespan.shutdown": + await send({"type": "lifespan.shutdown.complete"}) + return + + application = SentryAsgiMiddleware( ProtocolTypeRouter( { "http": get_asgi_application(), "websocket": URLRouter(websocket.websocket_urlpatterns), + "lifespan": LifespanApp, } ) )