Repository navigation
fix(start): stop the container when a poststart hook fails - #1173
Open
rahul05ranjan wants to merge 1 commit into
Open
rahul05ranjan wants to merge 1 commit into
rahul05ranjan wants to merge 1 commit into
Conversation
Per the OCI runtime spec, a failing poststart hook must stop the container and continue with the delete transition (runtime.md, lifecycle step 9). The previous error path returned from startUnikontainer without stopping the monitor, so the guest kept running, state.json still reported running and a plain urunc delete refused with 'cannot delete running container'. Mirror what delete --force already does in this situation and stop the monitor via unikontainer.Kill(), so a failed start reaches the same stopped state a killed container has. Fixes urunc-dev#1172 Co-authored-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com> Signed-off-by: rahul05ranjan <11793455+rahul05ranjan@users.noreply.github.com>
✅ Deploy Preview for urunc canceled.
|
This branch has not been deployed
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.
Description
urunc startreturns an error when a poststart hook fails, but leaves the container running:startUnikontainer()(cmd/urunc/start.go) sets the running state and then returnsExecuteHooks("Poststart")directly, without stopping the monitor. The guest keeps running,state.jsonstill reportsrunning, and since the monitor's init process still answers, a plainurunc delete(without--force) is refused withcannot delete running container— the container is left alive by a start that reported failure.The OCI runtime spec is explicit about this case:
(runtime.md, container lifecycle step 9.) runc kills the container on this path.
The fix mirrors what
urunc delete --forcealready does in the same situation (cmd/urunc/delete.go): stop the monitor withunikontainer.Kill(), which stops the VMM process and returns once the monitor has exited, leaving the release of the remaining resources to the delete transition — exactly "stop the container and continue with delete". The hook error is still returned; if the stop itself fails, both errors are joined so the caller sees the compound failure.Kill()on a monitor that never started is a no-op (State.Pid <= 0), so the path is safe for any state the start sequence could have reached. Both entry points that execute poststart hooks (urunc startandurunc run, which callsstartUnikontainer) get the behavior.Related issues
How was this tested?
4f6b879: the previousreturn unikontainer.ExecuteHooks("Poststart")was the only error path instartUnikontainerafterSetRunningState()that left the monitor alive (theAwaitMsg/startReexecfailures happen before the monitor reports a successful start and the reexec/monitor process tears down on its own);Delete()refuses viaisRunning()(syscall.Kill(Pid, 0)on the monitor pid), which is why the stopped-then-delete sequence is required rather than only a state write — urunc never persists astoppedstatus anddelete --forcealready relies onKill()for exactly this outcome.make lintnor the e2e suites (test_ctr/test_nerdctl/test_docker/test_crictl) were run locally. The change is a 12-line, single-file error path that reuses an existing, already-tested method; the runtime verification for this fix is the reproduction in urunc start leaves the guest running when a poststart hook fails #1172 (a bundle with a failing poststart hook, thenurunc start+urunc deletewithout--force).LLM usage
GLM (Z.ai, model glm-5.3, via OpenRouter) assisted in analyzing the issue, reading the runtime spec and preparing this change; the diff was reviewed line by line against the spec text quoted above and against urunc's own
delete --forcepath before opening.Checklist
make lint). — no Go toolchain on this machine; single-file change ingofmtstyle.make test_ctr,make test_nerdctl,make test_docker,make test_crictl). — needs a solo5 VMM and a unikernel image, not available here; CI will run the suite once labeled.