docker-py
docker-py copied to clipboard
Container.wait with timeout raises Connection Error
container = docker_client.containers.run(image = image,
command = cmd,
detach = True,
auto_remove = False,
)
container.wait(timeout = 10)
Without a timeout, everything works fine. With a timeout I get the following Exception: ConnectionError(ReadTimeoutError('None: None',),)
The API says it should be raising a requests.exceptions.ReadTimeout
Name: docker Version: 2.7.0 Summary: A Python library for the Docker Engine API. Home-page: https://github.com/docker/docker-py Author: Joffrey F Author-email: [email protected] License: Apache License 2.0 Location: /usr/local/lib/python3.6/site-packages Requires: six, websocket-client, requests, docker-pycreds
I am experiencing this as well. This started occuring after upgrading Docker from docker-engine 17.05 to docker-ce 18.03 on Ubuntu 16.04 LTS.
I can see some entries in the backtrace that seem to be related to reading chunked response; might this be related to https://github.com/requests/requests/issues/4402 ?
I already made this comment on #1374, but this seems to be a better place for it.
I'm still seeing this in 3.4.1:
OS: CentOS 7.5 Docker: 18.03
As before, it does not occur with the docker CLI, only the Python API.
In my case it occurs when running container.wait(). It originates with a socket.timeout exception in the urllib3 package, which sets off a cascade of other exceptions:
- socket.timeout
- urllib3.exceptions.ReadTimeoutError
- requests.exceptions.ConnectionError: UnixHTTPConnectionPool
It seems that requests is raising the wrong exception: requests.exceptions.ConnectionError instead of requests.exceptions.ReadTimeout. Shouldn't these exceptions be handled in the Docker API and converted to a public exception, rather than relying on the exception type from an underlying package?
I'm also experiencing this on 4.4.1.
I'm attempting to catch requests.exceptions.ReadTimeout as documented. However, no such error is catched. Instead, I'm presented with a trace of the same exceptions as @orodbhen
OS: Ubuntu 20.04.1 LTS Docker: 20.10.0
As a workaround, until the low level exceptions are converted to a docker-timeout-exception, I use
import requests
try:
result = container.wait(timeout=30)
except (requests.exceptions.ReadTimeout, requests.exceptions.ConnectionError):
# timeout occurred
pass
I have this issue on Fedora 36 as well.