Skip to content

Commit dbcbf97

Browse files
committed
fix(sandbox): read the engine as running only when docker info prints a version
The Docker 28.0 client exits 0 when no engine answers, with its error as the only output, so a refused socket read as a running engine whose version was the error. The engine now runs only when docker info exits 0 and its output parses as a version.
1 parent df66256 commit dbcbf97

2 files changed

Lines changed: 22 additions & 1 deletion

File tree

‎cli/src/coding_study/adapters/docker_sandbox.py‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import ipaddress
1414
import json
1515
import os
16+
import re
1617
import shutil
1718
import signal
1819
import subprocess
@@ -134,6 +135,9 @@
134135
_FORWARDER_SOURCE = Path(__file__).with_name("sandbox_forward.py")
135136
_MOCK_CODE_SOURCE = Path(__file__).with_name(MOCK_CODE_DIRECTORY)
136137
_PERMISSION_REFUSED = "permission denied"
138+
_ENGINE_VERSION = re.compile(r"\d+\.\d+(\.\d+)?([-+~][0-9A-Za-z.+~-]*)?")
139+
"""What `docker info` prints for an engine that answers, such as `29.8.1` or `20.10.24+dfsg1`. The
140+
Docker 28.0 client exits 0 when no engine answers, with its error as the only output."""
137141
_ENDING_SIGNALS = (signal.SIGINT, signal.SIGTERM)
138142
_START_THE_APP_ALONE = (
139143
*("up", "--detach", "--no-deps", "--no-recreate", "--no-build", *_PULL_NEVER),
@@ -314,7 +318,7 @@ def state(self) -> EngineState:
314318
if info is None:
315319
return EngineState(EngineStatus.NOT_INSTALLED)
316320
version = info.output.strip()
317-
if info.exit_code != 0 or not version:
321+
if info.exit_code != 0 or not _ENGINE_VERSION.fullmatch(version):
318322
status = _refused_or_stopped(info.output)
319323
if status is EngineStatus.NO_PERMISSION:
320324
return EngineState(status, docker_group=self._docker_group())

‎cli/tests/adapters/test_docker_sandbox.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,23 @@ def test_a_refused_socket_says_where_you_stand_with_the_docker_group(tmp_path, g
154154
assert state == EngineState(EngineStatus.NO_PERMISSION, docker_group=group)
155155

156156

157+
def test_a_refused_socket_on_a_client_that_exits_0_is_no_permission(tmp_path):
158+
"""Docker 28.0 prints nothing on standard output, the error on standard error, and exits 0."""
159+
docker = ScriptedDocker()
160+
refused = (
161+
"permission denied while trying to connect to the Docker daemon socket at "
162+
'unix:///tmp/r.sock: Get "http://%2Ftmp%2Fr.sock/v1.48/info": '
163+
"dial unix /tmp/r.sock: connect: permission denied\n"
164+
)
165+
docker.answer(("docker", "info"), ProbeResult(0, refused))
166+
docker.answer(("docker", "compose", "version"), ProbeResult(0, "2.38.2\n"))
167+
in_session = DockerGroup.IN_SESSION
168+
169+
state = sandbox(docker, tmp_path, platform="linux", docker_group=lambda: in_session).state()
170+
171+
assert state == EngineState(EngineStatus.NO_PERMISSION, docker_group=in_session)
172+
173+
157174
def test_an_engine_that_answers_or_is_stopped_looks_up_no_group(tmp_path):
158175
docker = ScriptedDocker()
159176
docker.answer(("docker", "info"), ProbeResult(1, "Cannot connect to the Docker daemon"))

0 commit comments

Comments
 (0)