-
-
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
Unexplained CancelledErrors Over Extended Period #2056
Comments
Do you use client session from aiohttp web handler? |
Yes, there is a single shared ClientSession object being stored in |
The issue is: client (or web browser) used for making requests to your web server sometimes closes or just looses connection to server. |
That's exactly right, the way to reproduce easily is to make a request on localhost with an nginx server setup like this:
Run a simple aiohttp server on 8080, and have an |
To be clean: this is expected behavior.
|
Ok thanks for clarifying that point. However, making this the case makes it difficult to protect against and/or respond to. How would you advise mitigating this (other than never having clients disconnect). The problem as I understand it is that it can be thrown on any async line of code anywhere in the server, and is indistinguishable from other ways that To be clear, in something like this, if I get past the
It just seems problematic to essentially make the client disconnecting able to disrupt the server code at essentially any line. |
Let me phrase it another way, I would expect failure point to be in responding to client perhaps (at the return point of web handler), or maybe a |
As another aside, suppose you have a long-running process that is updating many documents, and the client is awaiting a response, but its for display purposes only ( |
For protecting your code from cancellation you should spawn a new task. |
Please close issue. Everything is clearly explained. |
I tend to agree with @owsd, I'd imagine server should raise something like a ClientDisconnected error so differentiate between something that's expected, and unexpected. Cancelled errors are unexpected, ClientDisconnected are expected. |
@thehesiod there is no way to pass custom exception into |
I just came across this bug today. I'm confused as to why this bug was ever closed. AFAICT, there's no way to distinguish between the case where |
I feel your pain. |
Long story short
I am experiencing intermittent but frequent unexplained CancelledErrors under load in AIOHTTP2. I'm not sure if I am doing something wrong or their is an issue. Looking at server logs and metrics, I'm not seeing any evidence this is a downstream hangup on aiohttp. Within the aiohttp code, I catch the CancelledError and timed the aiohttp requests, and the cancellation is always immediate such as 0.001 seconds (timex).
Reading through the source code, it looks like this is in trying to acquire a future. I'm not sure if i'm bumping into some sort of limit or something?
This is an issue for me as i'm consistently losing many requests due to this.
Expected behaviour
CancelledErrors when valid to not be so immediate or frequent, and to be the result of a downstream timeout or similar.
Actual behaviour
Seeing sporadic cancelled errors, but consistently occurring over periods of multiple hours, all in the same place inside aiohttp of trying to acquire a future, and always immediate.
Steps to reproduce
Running many requests though an aiohttp server over time. ClientSession is shared across all requests. I currently have timeouts set as
ClientSession(loop=app.loop, read_timeout=120, conn_timeout=30)
Your environment
aiohttp 2.2.0, ubuntu, python 3.5,
The text was updated successfully, but these errors were encountered: