Skip to content

fix(sandbox): keep the Docker worker when a command exits 124 by itself - #796

Open
thecorporatetractor wants to merge 1 commit into
BaaRai:mainfrom
thecorporatetractor:fix/sandbox-exit-124
Open

thecorporatetractor wants to merge 1 commit into
BaaRai:mainfrom
thecorporatetractor:fix/sandbox-exit-124

Conversation

@thecorporatetractor

Copy link
Copy Markdown
Contributor

Problem

Since #764, the Docker backend removes the worker container when an exec times out. It detects the timeout by exit code 124 (sandbox/docker.go, timedOut := exitCode == 124).

artex-exec-wrap returns 124 when it enforces timeout_ms, but a command can also exit 124 by itself. coreutils timeout does, and agents use timeout N <tool> a lot. Such a command now removes the task's worker, and every background job and service in it stops. This was reported in the #764 review.

Repro on main, live Docker:

Exec(Argv: ["timeout","1","sleep","5"], TimeoutMS: 30000)
-> {ExitCode:124 TimedOut:true DurationMS:2163}, and the worker container is gone

Change

An exit 124 counts as the runner's timeout only when the exec ran for at least timeout_ms. The wrapper returns 124 only after its timer fires, so a genuine timeout always takes that long, and a shorter 124 is the command's own exit code. The fix needs no worker image change, so it works with any wrapper version.

Tests

  • New TestExecCommandExit124BeforeTimeoutKeepsWorker (fake Engine): exit 124 well before timeout_ms is reported with ExitCode: 124, TimedOut: false, and the worker is kept. It fails on main and passes here.
  • The existing timeout tests now let the fake exec run longer than timeout_ms, as a real timeout does.
  • New live test TestDockerCommandExit124KeepsWorker (ARTEX_SANDBOX_DOCKER_TEST=1): timeout 1 sleep 5 with timeout_ms 30000. It fails on main (TimedOut:true, worker removed) and passes here. The existing TestDockerTimeoutRemovesDetachedChild still passes, so a real timeout still removes the worker and its detached children.
  • go vet ./sandbox/ and go test -race ./sandbox/: pass.

the timeout by exit code 124. artex-exec-wrap returns 124 when it enforces
timeout_ms, but the command can also exit 124 itself: coreutils
`timeout 1 sleep 5` does. The runner then removed the worker and stopped
the task's background jobs after an ordinary inner timeout.

Count an exit 124 as the runner's timeout only when the exec ran for at
least timeout_ms, which is the only way the wrapper can return it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant