Skip to content
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

Django 5: log cancellation of async view #351

Closed
9 tasks done
jrobichaud opened this issue Oct 19, 2023 · 15 comments · Fixed by #413
Closed
9 tasks done

Django 5: log cancellation of async view #351

jrobichaud opened this issue Oct 19, 2023 · 15 comments · Fixed by #413
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@jrobichaud
Copy link
Owner

jrobichaud commented Oct 19, 2023

Django 5.0 now handles cancelling of async request:

async def my_view(request):
    try:
        # Do some work
        ...
    except asyncio.CancelledError:
        # Handle disconnect
        raise

See:

Todo:

function callAsync() {
    const abortController = new AbortController();
    fetch( "/async_view",  {
        method: 'get',
        signal: abortController.signal,
    })
    .then(function(response) {
        console.log("Async request completed");
    }).catch(function(error) {
        console.error(`Error: ${error}`);
    });
    setTimeout(()=>abortController.abort(), 10 )
}
@jrobichaud jrobichaud added the enhancement New feature or request label Oct 19, 2023
@jrobichaud jrobichaud changed the title Django 5: log disconnection in async response and streaming view Django 5: log cancellation in async response and streaming view Oct 19, 2023
@jrobichaud jrobichaud changed the title Django 5: log cancellation in async response and streaming view Django 5: log cancellation of async view and async streaming view Oct 19, 2023
@jrobichaud
Copy link
Owner Author

I managed implement streaming view support for both async and sync streaming responses in #353

However cancelling async views just freeze the asgi server.

I still don't know if I am doing something wrong or there is a bug in django.

Help would be appreciated.

@jrobichaud jrobichaud added the help wanted Extra attention is needed label Oct 28, 2023
@jrobichaud jrobichaud changed the title Django 5: log cancellation of async view and async streaming view Django 5: log cancellation of async view Oct 28, 2023
@mohamedTbarka
Copy link

@jrobichaud, can u please give more detail about the freezing of the ASGI server ?

@jrobichaud
Copy link
Owner Author

@mohamedTbarka

With an async view when cancelling a request with the client, the request does not end in django. Ex: the request_finished is never called.

Also, the asgi server is not taking any more requests. I have to restart it.

@mohamedTbarka
Copy link

@jrobichaud, thanks for ur feedback & colossal efforts regardin' this almighty package, I'll do my best to debug this issue guessin' it's a Django's bug !

1 similar comment
@mohamedTbarka
Copy link

@jrobichaud, thanks for ur feedback & colossal efforts regardin' this almighty package, I'll do my best to debug this issue guessin' it's a Django's bug !

@jrobichaud
Copy link
Owner Author

@mohamedTbarka thanks!, this is appreciated!

First of all make sure you can reproduce the bug

  1. First start the demo project
  2. Open the url
  3. Select the asgi tab
  4. Press the Async View button then press on the Cancel button within 1 second. It should reproduce the bug.

@mohamedTbarka
Copy link

@jrobichaud
I've reproduced the bug; debuggin' it, it' a Django's bug apparently !

@mohamedTbarka
Copy link

@jrobichaud, I'll open a ticket on "Django issues" if u confirm it of course !

@jrobichaud
Copy link
Owner Author

You are welcome to open a django ticket if you could spot the bug.

When you do, please add the link here please.

In order to make it easier for django to reproduce it, did you create a clean project from scratch to reproduce the bug? Referencing django-structlog may just cause confusion. What do you think?

@jrobichaud
Copy link
Owner Author

@mohamedTbarka did you submit django a ticket?

Django 5 release candidate is next week.

https://code.djangoproject.com/wiki/Version5.0Roadmap

@jrobichaud
Copy link
Owner Author

The bug is with django-allauth:

pennersr/django-allauth#3566

@mohamedTbarka
Copy link

@jrobichaud sorry for the delay due to some health issues, thanks for your precious feedback 🙏

@jrobichaud
Copy link
Owner Author

I am looking for the update of 0.60.0 of django-allauth.

@mohamedTbarka
Copy link

can u please explain in detail how django-allauth is the origin of the bug ?

@jrobichaud
Copy link
Owner Author

@mohamedTbarka pennersr/django-allauth#3566 their middleware is not compatible with async requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants