-
-
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
Concurrent clients in a single session raise ServerDisconnectedError: None #3530
Comments
GitMate.io thinks the contributor most likely able to help you is @asvetlov. Possibly related issues are #975 (aiohttp.ClientSession raises ServerDisconnectedError), #1175 (Unclosed client session warning), #2039 (Graceful shutdown for client sessions), #1686 (Client Session Timeouts - Usage Question), and #957 (Discarding cookies in client session). |
When I move import aiohttp
import asyncio
async def check_link():
async with aiohttp.ClientSession() as session:
async with session.get('http://127.0.0.1:8080/') as response:
content = await response.text()
print(repr(content))
async def main():
while True:
asyncio.create_task(check_link())
await asyncio.sleep(0.1)
asyncio.run(main()) |
Not sure what is your end goal but this should work: async def main():
async with aiohttp.ClientSession() as session:
while True:
await check_link(session)
await asyncio.sleep(.1) |
@jettify Yes, the variant with “non-overlapping” requests works, but I think the aiohttp client should be able to handle overlapping requests as well. This is just a minimal example to demonstrate the error. |
Try something like async with aiohttp.ClientSession() as session:
while True:
check_link(session)
await asyncio.sleep(.1) session should not sit inside loop. Also I suggest to add concurrency control for number active requests. |
@jettify is right. Let's return to the problem:
This code closes the session on exit from Obviously, the code is not correct. |
I see it. Of course 🤦♂️ I don't know why I haven't noticed the wrong placement of At least hopefully this issue may help somebody in future to debug similar mistakes :) Thank you for your work on aiohttp and other libs! |
you are welcome! |
It looks like the ClientSession connection pool does not handle correctly concurrent requests (but it's just my guess).
Server:
Client:
Output:
The exception repeats many times.
If remove the
await asyncio.sleep(.5)
or make it .01 then it works correctly, without any errors.Your environment
Tested on clean Docker image debian:buster with python3-venv. Same behavior observed also on macOS.
The text was updated successfully, but these errors were encountered: