fix(eval): reap orphaned eval containers on context cancellation#3586
Draft
aheritier wants to merge 1 commit into
Draft
fix(eval): reap orphaned eval containers on context cancellation#3586aheritier wants to merge 1 commit into
aheritier wants to merge 1 commit into
Conversation
exec.CommandContext only kills the docker CLI on ctx cancellation; the container it launched keeps running and --rm never fires, leaking long-lived eval containers (see #3585). Add a deferred reapContainer that force-removes the container on a fresh, detached context, respecting --keep-containers, and treats 'No such container' as benign. Also assign a bytes.Buffer to cmd.Stderr instead of using StderrPipe with a background goroutine, fixing a stderr data race and the incorrect Wait-before-pipe-drain ordering by construction. Adds daemon-free integration tests through runDockerAgentInContainer that protect the cleanup regression, and documents the behavior. Fixes #3585
16ba3cf to
219e8ce
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #3585. When a
docker agent evalrun is cancelled (timeout, Ctrl-C, or a per-eval failure cancelling the parent context), the per-eval containers launched with--rmwere orphaned rather than reaped.exec.CommandContextkills the docker CLI process on cancellation but never signals the container it started, so--rmcleanup never fires — leaving long-lived containers (observed 40+ min, runaway filesystem walks).Changes
reapContainer, deferred immediately aftercmd.Start()inrunDockerAgentInContainer, which force-removes the container viadocker rm -f <name>on a fresh, detached context (so it runs even when the eval context is already cancelled). Respects--keep-containersand treatsNo such containeras benign (the normal--rmhappy path).StderrPipe+ backgroundio.ReadAllgoroutine withcmd.Stderr = &bytes.Buffer{}, eliminating a pre-existing data race and the incorrect Wait-before-drain ordering by construction. Addedcmd.WaitDelay = 10shardening.runDockerAgentInContainer(fakedockeron PATH distinguishingrun/rm) covering caller-context cancellation, non-zero exit, scanner token-too-long, normal success, and--keep-containersskipping cleanup. Verified the regression is caught — removing thedeferfails 4 of 5.docs/features/evaluation/index.mdanddocs/features/cli/index.md.Validation
task build/task test/task lint— all cleango test -race ./pkg/evaluation— cleanFixes #3585