From e831e4fb94c5a1ba2d0477a2825472791860980b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Tue, 16 Nov 2021 13:25:03 +0100 Subject: [PATCH] root: add lifespan shim to prevent errors Signed-off-by: Jens Langhammer --- authentik/root/asgi.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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, } ) )