-
-
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
Cannot cancel reading from incoming connection and retry later #363
Comments
For my understanding, could you describe an use case of this need? What's the interest? |
Here is my usecase in more detail, thanks for your interest @GMLudo! My application is this one: https://github.com/saghul/CallRoulette In a nutshell, if a user connects, it waits until a new user connects and when we have 2, we start processing messages between the 2. Now, it's possible that while I wait for the second user to connect, the first one disconnects. In order to know about this, the only way is to use the receive() coroutine, AFAIK, together with my other coroutine, which waits for the second connection. Once the 2nd connection comes, I want to cancel the receive() I started and start the processing. In a nutshell, this looks like it was planned, there is even a related test about it, but it doesn't test the actual retrying. This also happens if you want to receive data with a timeout, AFAIS. |
Similar issue happens when user requests some URL that served by aiohttp with browser and hits Stop button / Esc in order to cancel page load (he tired to wait for the response, he change his mind etc.) - browser successfully terminates connection, but such assertion error occurs in logs. Things goes wild when you have users with unstable connection (mobile ones) - your logs are full of such assertions. |
@saghul change looks good, but it hard to tell if it safe. Usually we treat cancelation as disconnection. We should just cearfuly test this change. I can test it on one of my production instances. |
In my application I'm doing something like this:
This yields the following assertion error:
The problem looks quite obvious, in DataQueue.read the waiter is not reset until feed_data is called: https://github.com/KeepSafe/aiohttp/blob/master/aiohttp/streams.py#L364 and https://github.com/KeepSafe/aiohttp/blob/master/aiohttp/streams.py#L343
The solution, however, is not so obvious, here is a possible solution, let me know if you like the approach and I'll submit a PR with it:
For now I'm setting ws._reader._waiter to None after cancelling the task , which is quite ugly... :-S
The text was updated successfully, but these errors were encountered: