Skip to content

Fix container hang when Ctrl-C is pressed on apple runtime#13

Merged
ryanmoran merged 1 commit intomainfrom
apple-exec
Mar 21, 2026
Merged

Fix container hang when Ctrl-C is pressed on apple runtime#13
ryanmoran merged 1 commit intomainfrom
apple-exec

Conversation

@ryanmoran
Copy link
Owner

What

Fix a hang that occurred when pressing Ctrl-C while running contagent against the apple runtime.

Key changes:

  • Wrap the user command in a login shell (/bin/sh -l -c) in Container.Attach so profile files are sourced and PATH includes user-local directories
  • Replace direct SIGINT/SIGTERM signal handling in Container.Wait with ctx.Done() so Ctrl-C (which cancels the context in main.go) correctly triggers container shutdown
  • Add a 10-second timeout context to ForceRemove in the cleanup handler
  • Document the login shell as a temporary workaround, with removal instructions for when apple/container ships a release pinning containerization >= 0.26.5

Why

Two bugs in apple/containerization (PRs #550 and #562) caused container exec to ignore the container's configured PATH and fall back to a hardcoded default that omits user-local directories like ~/.local/bin. When the command couldn't be found, the container hung instead of exiting cleanly. The latest apple/container release (v0.10.0) pins containerization 0.26.3 and does not include these fixes.

Separately, Wait was listening for OS signals directly alongside a ctx.Done() case that only waited for the process without stopping the container — the ctx.Done() path would block forever if the container hung. Consolidating to ctx.Done() with a container stop call fixes this.

How to Test

  1. Run contagent against the apple runtime: contagent <command>
  2. Press Ctrl-C while the container is running
  3. Verify the container exits cleanly and does not hang

Notes

The login shell workaround is intentionally temporary. Removal steps are documented in a TODO comment in container.go.

Wrap the user command in a login shell in Container.Attach to work around
PATH resolution bugs in apple/containerization <= 0.26.3. Replace direct
signal handling in Container.Wait with ctx.Done() so Ctrl-C correctly
triggers container shutdown. Add a 10-second timeout context to ForceRemove
in the cleanup handler.
@ryanmoran ryanmoran merged commit 13708e6 into main Mar 21, 2026
1 check passed
@ryanmoran ryanmoran deleted the apple-exec branch March 21, 2026 22:08
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