aio-libs / aiodocker

Python Docker API client based on asyncio and aiohttp
Other
442 stars 101 forks source link

Cannot pass timeout to a show() or any other function, makes aiodocker hang long time #859

Open ualex73 opened 6 months ago

ualex73 commented 6 months ago

Long story short

How to reproduce

Setup connection, block connection with e.g. "iptables". Call the "show" of a container: outp = await self._container.show(timeout=3)

It does not timeout after 3 seconds, it hangs for many minutes. Also, debugging in "_do_query", I do not see the value passed to the function from the show.

Your environment

Debian 12, standard Docker

achimnol commented 5 months ago

In general, the recommended way to enforce timeout is to use asyncio.timeout() added in Python 3.11, instead of manually specifying the timeouts to all async APIs.

Timeouts in arbitrary async codes appear as cancellation from outside from the perspective of target codes.

See: https://docs.python.org/3/library/asyncio-task.html#asyncio.Timeout

achimnol commented 5 months ago

However, there are more subtle cases that you may want to control detailed connection timeout behavior like when accessing remote Docker instances via TCP, for example.

I think it would be a nice idea to expose aiohttp.ClientTimeout interface for aiodocker users to control more details.

Currently you can customize some parts of the timeout by passing your own created aiohttp connectors.