-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Web-handler cancellation #2098
Comments
First of all. As you say the behavior is normal so IMO with a big disclaimer in Now if we want to offer an alternative so handlers don't get cancelled sounds nice. If
|
'asyncio.shield' is not enough, cuz You'r app can be stopped at any moment and shield wouln't be finished |
Well, shield might be enough in many cases. But there is very common pattern: send response quickly and do all slow operations in background. |
asyncio cancel behaviour is very tricky business, and we had bunch of issues in other projects (in all our DB dirvers). I believe we should educate people and have separate entry in docs about cancel stuff as such question is most common one for new to aiohttp devs. Things I see we can do:
|
You're right there but I believe those are edge cases, I think the problem proposed here is more focused on an api that is not stopped where this problem still exists when the client disconnects. Anyway
Yeah, I don't argue with the use case about responding quickly and do slow operations in background. It's a necessary and nice tool but in the case you propose I believe
|
Sorry for possible off-topic, but there is how we have solved exactly this issue |
I think separate documentation section is enough. remember, we are not babysitters. |
Is it feasible to have an option to disable |
I do not think it is possible. CancelledError baked into asyncio so deep.
…Sent from my iPhone
On Jul 20, 2017, at 9:25 AM, Yegor Roganov ***@***.***> wrote:
Is it feasible to have an option to disable CancelledError's completely and have an ability on re-enable on per-handler basis? I understand why CancelledError may be great for microservices, but IMO for user-facing services it creates only problems by having business logic completed only partially (i.e., failing to send an email after committing a transaction, etc).
Obviously I can wrap all my handlers in aiojobs, but that would create overhead (though I didn't measure if it's substantial).
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.
|
i use aiojobs in python_socket.io,but it doesn't solve the problem. |
Fixed by #2257 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a [new issue] for related bugs. |
Now web-handler task is cancelled on client disconnection (normal socket closing by peer or just connection dropping by unpluging a wire etc.)
This is pretty normal behavior but it confuses people who come from world of synchronous WSGI web frameworks like flask or django.
The problem is: if web-handler writes a data to DB the task might be cancelled without waiting for transmission completion. The following snippet might be stopped on every line:
To make execution atomic user should spawn a task:
This approach is not reliable, new task is not awaited.
User need to use aiojobs:
Or maybe not existing yet:
Sure, I could document it in http://aiohttp.readthedocs.io/en/stable/web.html but not sure is it very visible and obvious way to protect from cancellation. Ideas?
The text was updated successfully, but these errors were encountered: