-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async view cancellation freeze asgi worker when using django-allauth #3566
Comments
allauth currently does not support async, see #3546. Likely, this needs to be applied to the middleware: https://docs.djangoproject.com/en/4.2/topics/http/middleware/#asynchronous-support Can you check if that fixes the issue? A PR is welcome. |
I have a fix for this in the pipeline... |
This could work I think: from asgiref.sync import iscoroutinefunction, markcoroutinefunction
from asgiref import sync
from allauth.core import context
from allauth.account import middleware
class AccountMiddleware(middleware.AccountMiddleware):
async_capable = True
sync_capable = True
def __init__(self, get_response):
self.get_response = get_response
if iscoroutinefunction(self.get_response):
markcoroutinefunction(self)
def __call__(self, request):
if iscoroutinefunction(self):
return self.__acall__(request)
return super().__call__(request)
async def __acall__(self, request):
with context.request_context(request):
response = await self.get_response(request)
await sync.sync_to_async(self._remove_dangling_login)(request, response)
return response I did it using inheritance but the classes would have to be merged. |
Doesn't |
You are right, it is not required. |
Updated: from asgiref.sync import iscoroutinefunction, markcoroutinefunction
from allauth.core import context
from allauth.account import middleware
class AccountMiddleware(middleware.AccountMiddleware):
async_capable = True
sync_capable = True
def __init__(self, get_response):
self.get_response = get_response
if iscoroutinefunction(self.get_response):
markcoroutinefunction(self)
def __call__(self, request):
if iscoroutinefunction(self):
return self.__acall__(request)
return super().__call__(request)
async def __acall__(self, request):
with context.request_context(request):
response = await self.get_response(request)
self._remove_dangling_login(request, response)
return response |
Django 5.0 introduced the cancellation of Async views.
But when using
django-allauth
'sallauth.account.middleware.AccountMiddleware
the asgi worker freezes indefinitely.This is a major problem.
Conditions:
allauth.account.middleware.AccountMiddleware
curl <view url>
thenctrl-c
before it finishes)I made a project to reproduce the problem:
https://github.com/jrobichaud/django-allauth-async-view-cancel
The text was updated successfully, but these errors were encountered: