Skip to content
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

Container.wait with timeout raises Connection Error #1966

Open
sheridp opened this issue Mar 19, 2018 · 8 comments
Open

Container.wait with timeout raises Connection Error #1966

sheridp opened this issue Mar 19, 2018 · 8 comments

Comments

@sheridp
Copy link

sheridp commented Mar 19, 2018

    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: joffrey@docker.com
License: Apache License 2.0
Location: /usr/local/lib/python3.6/site-packages
Requires: six, websocket-client, requests, docker-pycreds

@mpasternacki
Copy link

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.

@mpasternacki
Copy link

I can see some entries in the backtrace that seem to be related to reading chunked response; might this be related to psf/requests#4402 ?

@orodbhen
Copy link

orodbhen commented Jul 12, 2018

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?

@adnilsson
Copy link

adnilsson commented Feb 5, 2021

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

@gsalzer
Copy link

gsalzer commented Dec 10, 2021

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

@zwimer
Copy link

zwimer commented Jun 23, 2022

I have this issue on Fedora 36 as well.

@jrab89
Copy link

jrab89 commented May 14, 2024

I ran into this problem using version 7.0.0 of docker-py and version 3.11 of python. The docs say Container.wait raises requests.exceptions.ReadTimeout on a timeout, but it's raising requests.exceptions.ConnectionError.

@gsalzer
Copy link

gsalzer commented May 15, 2024

@jrab89 I observed this in 2021, see my comment above, and wasn't the first one at that. It seems that the maintainers of docker-py cannot, or don't want to, change it. There must be some obstacle that prevents them from catching low-level exceptions at the right places and raising a "docker-timeout-occurred" exception instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants