-
-
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
Request is not cancelled on timeout, its response is returned for the next request #7864
Comments
Hello, I can confirm we've hit the same issue in Rally (Elasticsearch benchmarking tool). elastic/rally#1804 |
This might be a side effect of using the callback done running with a call soon |
I see similar issues in our application. The following code exposes a problem on my machine (Python 3.11): import asyncio
import random
from typing import Any
import aiohttp
async def main() -> None:
# Usually works when this is `<= 100`
num_calls = 120
client = aiohttp.ClientSession()
async def call(n: int) -> Any:
# This service echoes the request body in the response
# The random timeout is key here, it works when `timeout=None`
response = await client.put(
"http://localhost:3000/", timeout=random.random(), json={"n": n}
)
body = await response.text()
return (n, body)
results = await asyncio.gather(
*[call(i) for i in range(num_calls)], return_exceptions=True
)
for result in results:
if isinstance(result, Exception):
print(type(result))
else:
print(result)
await client.close()
asyncio.run(main()) On version 3.8.6 this does what you would expect with the n in the request and in the response matching:
However, on 3.9.0, we see this:
We also saw other unexplainable behaviour that could be caused by this, but I have no evidence nor re-production of that. |
Does anyone have a working test case we can merge as an xfail test so we can validate a fix? |
bisected this to #7764 |
Yeah, I already assumed it would be related to that. Something to do with us previously closing the connection and now we're trying to reuse it. |
Describe the bug
I see this strange behaviour in version 3.9.0 when I iterate to retry timed out request. It started with version 3.9.0b1.
Version 3.9.0b0 works as expected.
The probelm is when the initial request times out it should get cancelled, and indeed that iteration catches TimeoutError. The next iteration, which retries the request with new parameters somehow returns the response of the inittial cancelled request...
Please see the minimal reproducing example.
To Reproduce
Expected behavior
Correct results with 3.9.0b0
Logs/tracebacks
Python Version
aiohttp Version
multidict Version
yarl Version
OS
Ubuntu Linux
Related component
Client
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: