-
-
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
ServerDisconnectedError on subsequent requests only on Py 3.8 #4549
Comments
Looks like this is a good starting point for debugging. Could you please specify a few URLs where this explodes and (separately) a few URLs where it works. Also, is your Python interpreter coming from some public OS distro or did you compile it? |
I tried google.com for example, where it worked on 3.8. As for python interpreter, pyenv, as far as I know, compiles from source. But I tried it on Manjaro/Archlinux's Python 3.8.1 on which it also failed. |
Is this happening to both HTTP and HTTPS URLs? |
Yes, it happens on both https and http. |
I've found the same problem in python |
It seems that there is a bug in aiohttp lib for this version of Python. See: aio-libs/aiohttp#4549
Why this got tagged with reproducer:missing? I provided code snippet, which I believe highlights the issue clearly enough. Was it not possible to reproduce? |
I cannot reproduce this issue with the code snippet you provided running with python 3.8.1 on Archlinux, but I do have a similar issue as @gligneul with a test server on localhost. |
@Gargauth I don't remember why exactly but I probably marked is as missing because it looked like it's not enough. Now that I confirmed that it's reproducible under 3.8-dev from pyenv (on my Gentoo laptop), I can safely mark it as present. |
@Gargauth please provide HTTP URL with this issue happening. Changing your current reproducer URLs to plain HTTP does not explode. This is needed to confirm if it's related to TLS and it's what's unstable about your reproducer ATM. By the way, the best way to share a reproducer is to contribute a reliably failing test and mark it as |
I got this problem on Python 3.8.4 (Windows) too. |
aio-libs/aiohttp#4549 suggests the issue started in 3.8
I am seeing the same error, but on Python 3.6 (Ubuntu 20.04.1 LTS). The first request would succeed, the second would consistently and immediately fail. Per @WH-2099, Using versions: |
Does anybody have any other URLs that this happens on? Trying a few URLs, only the one in the reproducer triggered the issue for me. I see the error with the original code, but |
In fact I spent a lot of time trying to solve the same problem when I intuitively found these three issues.
In general, I think these issues are clearly related to the change in the Python 3.8 asyncio module to change the default event loop.https://docs.python.org/3/library/asyncio-platforms.html And the most important feature that manifests itself is premature disconnection from the underlying connection to the server. |
Not sure if it changes your theory, but I reproduced the example for this on Linux, which is not using the ProactorEventLoop. I did not try testing in Python 3.7 though. |
I am experiencing this with Python 3.9.6 running inside Docker container (official Python image, tag Requests are being sent to: It is possible to overcome it with And it doesn't happen with the |
I can't reproduce with any of those URLs, still only the original URL. Also, I've just realised I was reproducing it in an lxc container, but I can't reproduce the issue on my host. One additional datapoint is that the issue also seems to only appear if reading from the response (i.e. no error when removing |
@Dreamsorcerer Thanks for the reminder, I'm mainly using the windows platform and am not very familiar with linux, so I was not thinking well. It looks like the event loop is not the culprit. However, I still intuitively think that these issues may be caused by the same problem at the bottom. |
@Dreamsorcerer here is the piece of code which reproduces the issue for me consistently both inside the docker container (Python 3.9.6), on the Ubuntu (WSL, Python 3.8.10) and on the Windows host (Python 3.9.6). It uses
It will be asking you for the username and password - you can enter any random data. After that it tries to login again and gives me Strange that |
python 3.10.6 Same problem. With |
python 3.10.6 (docker image Same problem here. about 5%-10% chances the second request would raise |
Maybe it will be useful
problem 'solved'
|
Hi! python 3.9.18, aiohttp 3.6.2 -> problem is reproduced (using @Gargauth 's script) Can someone explain please, was it fixed in the latest aiohttp versions? Where and how? Just curious :) Edit: |
I can confirm that I am facing this issue on macOS Sonoma 14.0 with Python The disconnects were random, but they seem to stop after I added the short async def get_data(session: aiohttp.ClientSession, api_url: str) -> dict:
async with session.get(api_url) as response:
await asyncio.sleep(0.001)
resp_as_json = await response.json()
return resp_as_json |
Adding async with session.get(url) as response:
await asyncio.sleep(0)
upload(response.content) |
Same issue for me on home assistant 2024.1.0 with aiohttp 3.9.1. Sometimes I randomly get a client error: "Server disconnected". |
|
@bdraco here's someone mentioning HA, FYI |
I am having this issue in HA for 1.5 years now. If someone else is having this issue with home assistant and needs more reliability in triggering web commands, I found an alternative using curl: In the past I used rest_commands, which are using aiohttp, like this:
... and then in an automation Here is a very reliable alternative with shell_commands and curl, where you also can define retry options:
To trigger that service in an automation use Curl has been very reliable for me in past projects, so I hope this will finally solve the issue for me. |
It seems that #7363 is likely to solve that issue |
Ok, fingers crossed! But anyways, I prefer using curl as I am very used to it and finally found an easy way to use it from HA and also parametrize it the same way like rest_commands |
I got this error with http://www.oxfordlearnersdictionaries.com/us/wordlists/oxford3000-5000 |
I can't reproduce anymore, so I suspect the issue was caused by a questionable server closing the connection immediately after saying it would keep it alive. New versions automatically retry, thus working around the problem. |
🐞 Describe the bug
Aiohttp throws
aiohttp.ServerDisconnectedError
on 3.8.1 on subsequent requests within scope of single ClientSession, but only on certain domains. There is no such issue on older Python 3.7.6 so it shouldn't be issue on remote server.💡 To Reproduce
await asyncio.sleep(0.0001)
(this is just for experimentation, to demonstrate that somehow this issue doesn't occur when there's sleep).💡 Expected behavior
Both requests should complete successfully sequentially - just like on Python 3.7.
📋 Logs/tracebacks
📋 Your version of the Python
📋 Your version of the aiohttp/yarl/multidict distributions
📋 Additional context
aiohttp client. Python 3.8.1 (pyenv), venv installed via poetry.The text was updated successfully, but these errors were encountered: