Skip to content

fix(client): clean up after a build interrupted by Ctrl-C - #299

Merged
jochumdev merged 2 commits into
fix/podman-remote-buildfrom
fix/build-interrupt-cleanup
Dec 1, 2026
Merged

jochumdev merged 2 commits into
fix/podman-remote-buildfrom
fix/build-interrupt-cleanup

Conversation

@tallica

@tallica tallica commented Nov 29, 2026 •

Copy link
Copy Markdown
Collaborator

Stacked on #297 (fix/podman-remote-build), which this PR targets. It needs the
bounded rm/rmi cleanup from there. Once #297 merges, retarget this to main.

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-* image
behind, and with a remote podman (#297) the export container too. Verified
live in a podman VM: Ctrl-C during podman export left 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

  • incus-compose never catches SIGINT, so Go's default handling exits before
    any deferred call runs.
  • buildImage (client/resource_image.go) now runs the builder call under
    signal.NotifyContext(ctx, os.Interrupt, syscall.SIGTERM) and stops
    listening right after it returns. The cancel reaches the builder, whose
    deferred rm/rmi run on their own bounded context (fix(client): build with a remote podman #297).
  • context.AfterFunc(buildCtx, stopSignals) drops the handler as soon as the
    first signal arrives, so the next one gets the default behaviour (kill).
  • Only the build catches the signal, not the whole program: the Incus client
    keeps the root context for its calls, and attached up runs down on it
    after Ctrl-C ends the log stream. A program-wide cancel would make that
    down fail.

Test plan

  • New e2e TestBuildCommandInterrupt runs the real binary with
    build --builder <fake podman>. The fake reports remote and its
    export hangs.
    - cleans up: one SIGINT during export; rm and rmi both run.
    Without the fix neither runs.
    - second interrupt exits: the fake rm hangs; a second SIGINT kills
    the process within 10s. Without the AfterFunc it waits out the
    stuck rm (20s).
  • just test-e2e ./cmd/incus-compose/ -run Build with docker: 14/14
  • just fix clean on ./client/ and ./cmd/incus-compose/
  • Live against a real podman machine VM on macOS (remote podman, x86_64
    Incus), Ctrl-C sent to the whole process group like a terminal does:
    - during podman export of a 600 MB image: rm then rmi ran, the
    command failed with exporting rootfs: signal: interrupt, no container
    or build image left (before the fix: both were left)
    - during podman build: failed with signal: interrupt, nothing left
  • A second signal within microseconds of the first can be dropped (the
    handler is removed on a goroutine); the next one kills. Accepted as is
  • Not tested on Windows; the test is skipped there because
    os.Interrupt cannot be sent

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
tallica force-pushed the fix/build-interrupt-cleanup branch from ebcff27 to ec40848 Compare November 29, 2026 20:43
@tallica tallica mentioned this pull request Nov 29, 2026
7 of 10 tasks
@jochumdev
jochumdev merged commit 743455a into fix/podman-remote-build Dec 1, 2026
9 of 10 checks passed
@jochumdev
jochumdev deleted the fix/build-interrupt-cleanup branch December 1, 2026 23:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants