Skip to content

Conversation

@Ronitsabhaya75
Copy link
Contributor

…ternal termination

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

Motivation and Context

Resolves #1050.

When containers are killed externally (via kill or launchctl bootout), the XPC connection loss causes the wait handler to throw an .interrupted error. This prevents cleanup and leaves containers stuck in running state.

Fix: Modified the wait handler in ContainersService.swift to catch .interrupted errors and treat them as container exits (code 137), allowing normal cleanup to proceed.

let waitFunc: ExitMonitor.WaitHandler = {
    log.info("registering container \(id) with exit monitor")
    do {
        let code = try await client.wait(id)
        log.info("container \(id) finished in exit monitor, exit code \(code)")
        return code
    } catch let err as ContainerizationError where err.code == .interrupted {
        // XPC connection was lost (e.g., container killed externally).
        // Treat this as a container exit so cleanup can proceed.
        log.warning("container \(id) XPC connection lost, treating as external termination")
        return ExitStatus(exitCode: 137)  // SIGKILL
    }
}

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

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.

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

1 participant