Skip to content

[Bug]: Container is showing as running even after being killed #1050

Closed

Description

@vsarunas

I have done the following

  • I have searched the existing issues
  • If possible, I've reproduced the issue using the 'main' branch of this project

Steps to reproduce

Hi @jglogan !

While testing #1041 using the kill script in #614, I had noticed that state of the container is not updated if it is killed via kill or launchctl bootout.

Start a container:

container run --name alpine-sleep-$(date +%H%M) --detach alpine sleep infinity
container list
ID                 IMAGE                            OS     ARCH   STATE    ADDR             CPUS  MEMORY   STARTED
alpine-sleep-1648  docker.io/library/alpine:latest  linux  arm64  running  192.168.64.2/24  4     1024 MB  2026-01-14T15:48:52Z

Kill:

launchctl list | grep "com.apple.container.*alpine-sleep" | awk '{print $1}' | xargs kill

Container is showing as running:

container list
ID                 IMAGE                            OS     ARCH   STATE    ADDR             CPUS  MEMORY   STARTED
alpine-sleep-1648  docker.io/library/alpine:latest  linux  arm64  running  192.168.64.2/24  4     1024 MB  2026-01-14T15:48:52Z

Failing to be stopped:

2026-01-14T16:52:11+0100 error com.apple.container: [ContainerCommands] failed to stop container alpine-sleep-1648: internalError: "failed to stop container" (cause: "internalError: "failed to stop container alpine-sleep-1648 (cause: "interrupted: "XPC connection error: Connection invalid"")"")
Error: internalError: "stop failed for one or more containers alpine-sleep-1648"

Still showing as running:

 container list
ID                 IMAGE                            OS     ARCH   STATE    ADDR             CPUS  MEMORY   STARTED
alpine-sleep-1648  docker.io/library/alpine:latest  linux  arm64  running  192.168.64.2/24  4     1024 MB  2026-01-14T15:48:52Z

State will be updated only after full system stop:

container system stop
container system start

Current behavior

Container is shown as running; cannot be stopped and continues to be shown as running until container system stop.

Expected behavior

Update container system state if the container exited outside of container.

Environment

- OS: macOS 26.2
- Xcode: 26.2
- Container: container CLI version 0.7.1-49-gdbec1db (build: release, commit: dbec1db)

Relevant log output

N/A

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. added theissue type on Jan 14, 2026
  2. Ronitsabhaya75 commented on Jan 15, 2026

    @Ronitsabhaya75
    Contributor

    Hi @vsarunas ! Thanks for the detailed report.

    Root Cause:

    • When containers are killed externally, the XPC connection is lost
    • The wait handler throws .interrupted error, preventing state cleanup
      Fix:

    Modified

    • ContainersService.swift (lines 364-376) to catch XPC connection errors
    • Now treats connection loss as container exit (code 137 = SIGKILL)
    • Allows normal cleanup flow to update state to stopped
  3. added a commit that references this issue on Jan 15, 2026
    23f96cb
  4. jglogan commented on Jan 15, 2026

    @jglogan
    Contributor

    For comparison here's what shows up in the logs if I kill the com.apple.Virtualization.VirtualMachine process:

    % container system logs -f
    Warning! Running debug build. Performance may be degraded.
    Filtering the log data using "subsystem ==[cd] "com.apple.container""
    Timestamp                       Thread     Type        Activity             PID    TTL  
    2026-01-15 08:06:19.968901-0800 0xd815e4   Error       0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] WaitHandler for 8fe16aad-503e-4e26-a3af-928ee8d1ec2b threw error internalError: "failed to wait on process" (cause: "unavailable (14): Transport became inactive") [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.974957-0800 0xd815e4   Info        0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] init process exited with: ExitStatus(exitCode: -1, exitedAt: 2026-01-15 16:06:19 +0000) [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.979110-0800 0xd815e4   Error       0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] failed during guest cleanup: internalError: "failed to dial agent" (cause: "Error Domain=VZErrorDomain Code=3 "The virtual machine is no longer live." UserInfo={NSLocalizedFailure=Invalid virtual machine state., NSLocalizedFailureReason=The virtual machine is no longer live.}") [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.979483-0800 0xd815e4   Error       0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] failed to delete init process: internalError: "failed to delete process" (cause: "unavailable (14): The connection was dropped and a reconnect was not configured") [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.979513-0800 0xd815e4   Error       0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] failed to stop VM: invalidState: "vm is not running" [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.979713-0800 0xd815e4   Error       0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] failed to stop container during cleanup: internalError: "failed to dial agent" (cause: "Error Domain=VZErrorDomain Code=3 "The virtual machine is no longer live." UserInfo={NSLocalizedFailure=Invalid virtual machine state., NSLocalizedFailureReason=The virtual machine is no longer live.}") [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.979725-0800 0xd815e4   Info        0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] closing forwarders [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.979746-0800 0xd815e4   Info        0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] closed forwarders [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:19.981745-0800 0xd80985   Info        0x0                  49380  0    container-network-vmnet: [com.apple.container:NetworkVmnetHelper] released attachments [id=default] [hostname=8fe16aad-503e-4e26-a3af-928ee8d1ec2b.test.]
    2026-01-15 08:06:19.988520-0800 0xd80987   Info        0x0                  49375  0    container-apiserver: [com.apple.container:APIServer] container 8fe16aad-503e-4e26-a3af-928ee8d1ec2b finished in exit monitor, exit code ExitStatus(exitCode: -1, exitedAt: 2026-01-15 16:06:19 +0000)
    2026-01-15 08:06:19.989123-0800 0xd80987   Info        0x0                  49375  0    container-apiserver: [com.apple.container:APIServer] Handling container 8fe16aad-503e-4e26-a3af-928ee8d1ec2b exit. Code ExitStatus(exitCode: -1, exitedAt: 2026-01-15 16:06:19 +0000)
    2026-01-15 08:06:19.989230-0800 0xd80987   Info        0x0                  49375  0    container-apiserver: [com.apple.container:APIServer] Shutting down sandbox service for 8fe16aad-503e-4e26-a3af-928ee8d1ec2b
    2026-01-15 08:06:19.990643-0800 0xd81a39   Info        0x0                  53540  0    container-runtime-linux: [com.apple.container:RuntimeLinuxHelper] `shutdown` xpc handler [uuid=8fe16aad-503e-4e26-a3af-928ee8d1ec2b]
    2026-01-15 08:06:20.052685-0800 0xd80987   Info        0x0                  49375  0    container-apiserver: [com.apple.container:APIServer] Deregistered sandbox service for 8fe16aad-503e-4e26-a3af-928ee8d1ec2b
    
  5. jglogan commented on Jan 15, 2026

    @jglogan
    Contributor

    Here's the log output when killing container-runtime-linux process:

    % container system logs -f
    Warning! Running debug build. Performance may be degraded.
    Filtering the log data using "subsystem ==[cd] "com.apple.container""
    Timestamp                       Thread     Type        Activity             PID    TTL  
    2026-01-15 08:12:37.231076-0800 0xd83bb8   Error       0x0                  49375  0    container-apiserver: [com.apple.container:APIServer] WaitHandler for 2bcd1454-0c39-4ff1-9162-7b37ccc6af16 threw error internalError: "failed to wait for process 2bcd1454-0c39-4ff1-9162-7b37ccc6af16 in container 2bcd1454-0c39-4ff1-9162-7b37ccc6af16" (cause: "interrupted: "XPC connection error: Connection interrupted"")
    2026-01-15 08:12:37.231294-0800 0xd83bb8   Info        0x0                  49375  0    container-apiserver: [com.apple.container:APIServer] Handling container 2bcd1454-0c39-4ff1-9162-7b37ccc6af16 exit. Code ExitStatus(exitCode: -1, exitedAt: 2026-01-15 16:12:37 +0000)
    2026-01-15 08:12:37.231368-0800 0xd83bb8   Info        0x0                  49375  0    container-apiserver: [com.apple.container:APIServer] Shutting down sandbox service for 2bcd1454-0c39-4ff1-9162-7b37ccc6af16
  6. added 2 commits that reference this issue on Jan 27, 2026
    6a8be2e
    25cae1e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions