docker/docker-py

socket timeout when docker exec lasts too long

loic-slamcore opened this issue · 2 comments

Since docker-py 6.1.0, using container.exec_run raises a socket.timeout exception if the command executed exceeds the timeout set on sockets when initialising the client.
This can be reproduced with the following code:

import docker
client = docker.from_env(timeout=2)
cnt = client.containers.run("ubuntu:22.04", tty=True, detach=True)
cnt.exec_run("sleep 20")

This was introduced by this PR because the previous call to select.select would only listen for reads, whereas the call to poll.register also listens to POLLOUT events.

I guess there's a case for raising timeout errors but ignoring them was previously working just fine so in my eyes, no exception should be raised especially as the polling can wait until the socket really is available for read instead.

This has been reproduced with the following setup:

pip freeze | grep docker && python --version && docker version
docker==6.1.1
Python 3.11.3
Client: Docker Engine - Community
 Version:           23.0.6
 API version:       1.42
 Go version:        go1.19.9
 Git commit:        ef23cbc
 Built:             Fri May  5 21:18:22 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.6
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.9
  Git commit:       9dbdbd4
  Built:            Fri May  5 21:18:22 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.21
  GitCommit:        3dce8eb055cbb6872793272b4f20ed16117344f8
 runc:
  Version:          1.1.7
  GitCommit:        v1.1.7-0-g860f061
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

I raised #3125 to resolve this issue.

milas commented

Fixed in 6.1.2. Thanks for raising the issue and fix!