exec_run timeout while command still in progress
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 7.2k
- Forks
- 1.7k
- Avg merge
- 13d 8h
- Merged PRs (30d)
- 2
Description
Hello,
I recently bump into something that look like a bug.
Explanation
I have a python script that exec a command in a container. That command can take some times ( ~10 minutes)
client.containers.get("container_name").exec_run(["/bin/bash", "-c", "command"])
Even if the command is still executing on the remote container, I receive the following error
Traceback (most recent call last):
File "backup.py", line 268, in <module>
backup.method(list[0])
File "backup.py", line 67, in backupGitLab
result = client.containers.get(container_name).exec_run(["/bin/bash", "-c", "command"])
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/models/containers.py", line 185, in exec_run
resp['Id'], detach=detach, tty=tty, stream=stream, socket=socket
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/utils/decorators.py", line 19, in wrapped
return f(self, resource_id, *args, **kwargs)
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/api/exec_api.py", line 165, in exec_start
return self._read_from_socket(res, stream, tty)
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/api/client.py", line 377, in _read_from_socket
return six.binary_type().join(gen)
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/utils/socket.py", line 75, in frames_iter
n = next_frame_size(socket)
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/utils/socket.py", line 62, in next_frame_size
data = read_exactly(socket, 8)
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/utils/socket.py", line 47, in read_exactly
next_data = read(socket, n - len(data))
File "/home/gaetan/.local/lib/python2.7/site-packages/docker/utils/socket.py", line 31, in read
return socket.recv(n)
socket.timeout: timed out
Even if the command is still running on the container, I receive a timeout error
Reproduction
I was able to reproduce this using the following code
client = docker.from_env(timeout=10)
result = client.containers.get(container_name).exec_run(["/bin/bash", "-c", "sleep 60"])
Expected behavior
The script should excute the sleep 60 command, and then end the script
Current behavior
I receive the same timeout error as the one above. Even if the command is still running ( and not in an error mode).
Timeout should occurs only when the command is not responding
Workaround
Set the timeout config to 600 secondes, in order to not have a timeout error
client = docker.from_env(timeout=600)
Questions
Is there any way to wait for a exec_run to finish ?
And is this a bug, because timeout should be receive only if a command is in error ?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with docker/models/containers.py exec_run and follow the call into docker/api/exec_api.py exec_start, docker/api/client.py _read_from_socket, and docker/utils/socket.py. Run the reported client.containers...exec_run(..., "sleep 60") reproduction with a 10-second timeout, then verify that a long-running responsive command can finish without an unintended socket timeout while genuine timeout behavior remains defined.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, python
- Domain
- api, devops
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100