docker-py icon indicating copy to clipboard operation
docker-py copied to clipboard

Container.wait with timeout raises Connection Error

Open sheridp opened this issue 7 years ago • 8 comments

    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

sheridp avatar Mar 19 '18 23:03 sheridp

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 avatar Apr 01 '18 18:04 mpasternacki

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 ?

mpasternacki avatar Apr 01 '18 18:04 mpasternacki

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?

orodbhen avatar Jul 12 '18 17:07 orodbhen

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

adnilsson avatar Feb 05 '21 15:02 adnilsson

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

gsalzer avatar Dec 10 '21 21:12 gsalzer

I have this issue on Fedora 36 as well.

zwimer avatar Jun 23 '22 22:06 zwimer