Repository navigation
fix(client): clean up after a build interrupted by Ctrl-C - #299
Merged
Merged
Conversation
incus-compose never catches SIGINT, so Ctrl-C during a build killed the process before the builder's deferred cleanup ran, leaving its temporary image and podman's export container behind. The builder call now runs under signal.NotifyContext, so the first Ctrl-C or SIGTERM cancels the build and the cleanup runs. The handler is dropped right after, so a second signal kills the process as before if a cleanup hangs. Only the build catches the signal: the client keeps the root context for its Incus calls, and attached up runs down on it after Ctrl-C. Signed-off-by: Michał Lipski <michal@tallica.pl>
tallica
force-pushed
the
fix/build-interrupt-cleanup
branch
from
November 29, 2026 20:43
ebcff27 to
ec40848
Compare
7 of 10 tasks
Signed-off-by: René Jochum <rene@jochum.dev>
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.
Stacked on #297 (
fix/podman-remote-build), which this PR targets. It needs thebounded
rm/rmicleanup from there. Once #297 merges, retarget this tomain.What changes for users
Pressing Ctrl-C during an image build used to kill incus-compose before the
builder could clean up. That left the temporary
ic-compose-build-*imagebehind, and with a remote podman (#297) the export container too. Verified
live in a podman VM: Ctrl-C during
podman exportleft both.Now the first Ctrl-C (or SIGTERM) during a build cancels it, the leftovers are
removed, and the command fails as it would for any failed build. A second
Ctrl-C kills the process as before, in case cleanup hangs on the daemon.
Ctrl-C at any other time is unchanged.
How it works
any deferred call runs.
buildImage(client/resource_image.go) now runs the builder call undersignal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM)and stopslistening right after it returns. The cancel reaches the builder, whose
deferred
rm/rmirun on their own bounded context (fix(client): build with a remote podman #297).context.AfterFunc(buildCtx, stopSignals)drops the handler as soon as thefirst signal arrives, so the next one gets the default behaviour (kill).
keeps the root context for its calls, and attached
uprunsdownon itafter Ctrl-C ends the log stream. A program-wide cancel would make that
downfail.Test plan
TestBuildCommandInterruptruns the real binary withbuild --builder <fake podman>. The fake reports remote and itsexporthangs.-
cleans up: one SIGINT duringexport;rmandrmiboth run.Without the fix neither runs.
-
second interrupt exits: the fakermhangs; a second SIGINT killsthe process within 10s. Without the
AfterFuncit waits out thestuck
rm(20s).just test-e2e ./cmd/incus-compose/ -run Buildwith docker: 14/14just fixclean on./client/and./cmd/incus-compose/Incus), Ctrl-C sent to the whole process group like a terminal does:
- during
podman exportof a 600 MB image:rmthenrmiran, thecommand failed with
exporting rootfs: signal: interrupt, no containeror build image left (before the fix: both were left)
- during
podman build: failed withsignal: interrupt, nothing lefthandler is removed on a goroutine); the next one kills. Accepted as is
os.Interruptcannot be sent