Skip to content

[Bug]: XPC Communication Race Conditions #167

Open
6 of 7 issues completed
Open

Description

@vladlen-codes

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

It complex asynchronous patterns with locks and task coordination that could lead to race conditions.

Current behavior

Asynchronous Message Handling

  • XPC messages are processed asynchronously
  • Multiple handlers can be active simultaneously for different requests
  • No clear synchronization between related operations

Shared Resource Access

  • Multiple XPC requests can access shared resources (containers, networks, etc.)
  • Lock usage is inconsistent across the codebase
  • Some operations appear to assume sequential execution

Callback Management

  • Completion handlers are used throughout the XPC communication
  • There's potential for callbacks to be invoked in unexpected order
  • Some callbacks may never be called if a race condition occurs

State Transition Issues

  • Container state transitions may not be properly synchronized
  • Operations could be attempted on containers in incompatible states
  • Race between status checks and operations

Expected Behavior

Synchronization
Atomic State Transitions

  • Container state changes should be atomic operations
  • State transitions should use appropriate locking mechanisms
  • State should be consistent across all components

Access Control

  • Shared resources should have clear ownership models
  • Consistent lock acquisition order to prevent deadlocks
  • Fine-grained locking to avoid unnecessary contention

Thread-Safe Message Handling

  • XPC message handlers should be thread-safe
  • Concurrent requests should not interfere with each other
  • Service implementations should handle overlapping requests correctly

Error Handling
Consistent Error Propagation

  • Errors should be properly propagated through the XPC hierarchy
  • Failure states should be clearly communicated to clients
  • Timeouts should be implemented for all operations

Graceful Recovery

  • The system should recover from communication failures
  • Resources should be properly released even when operations fail
  • Failed operations should leave the system in a consistent state

Callback Execution
Callback Invocation

  • Each callback should be invoked exactly once
  • Callbacks should occur even if the connection is terminated
  • Proper timeout and cancellation handling

Ordered Execution

  • Operations with dependencies should be executed in the correct order
  • Results should be delivered in a predictable sequence
  • Long-running operations shouldn't block critical path operations

Environment

- OS: macOS 26 Beta 1
- swift: Apple Swift version 6.2
- xcode: Xcode 26 Beta 17A5241e
- container: container CLI version 0.1.0

Relevant log output

[2025-06-12 14:32:15.234] [container-apiserver] [INFO] Received request to start container ID: abc123
[2025-06-12 14:32:15.235] [container-runtime-linux] [DEBUG] Processing start request for container abc123
[2025-06-12 14:32:15.236] [container-apiserver] [INFO] Received state request for container ID: abc123
[2025-06-12 14:32:15.237] [container-runtime-linux] [ERROR] Container state request while transition in progress
[2025-06-12 14:32:15.240] [container-runtime-linux] [DEBUG] Container abc123 state changed to: starting
[2025-06-12 14:32:15.242] [container-apiserver] [WARN] Concurrent operations detected on container abc123
[2025-06-12 14:32:15.245] [container-runtime-linux] [ERROR] Failed to complete container startup: resource lock timeout
[2025-06-12 14:32:15.250] [container-apiserver] [ERROR] XPC message response timeout: start_container

Code of Conduct

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

Sub-issues

Sub-issues

6 of 7 Issues completed
Loading 7 sub-issues

Activity

  1. heckj commented on Apr 11, 2026

    @heckj
    Contributor

    While this isn't stopping anything I'm doing, I think I'm running into this same issue. I'm using harbor framework to drive repeated container invocations, and on some of them when it's shutting down and cleaning up, I'm getting an error message:

    Error: internalError: "failed to stop container" (cause: "internalError: "failed to stop container ... (cause: "internalError: "XPC timeout for request to .../.../stop"")"
    

    Update: I've recently been using Container to run sequences of agent evaluation invocations using Harbor framework - and while it works, any run of 100 or more iterations will typically leave stopped containers not cleaned up, often leaking 2GB per container in my scenarios. The end result is that an eval doesn't get close to completing before I fill my local disk. Harbor does a good job of recovering, but in the meantime my workaround is:

    container system stop
    container system start
    container prune

    And then resuming my evaluation. I tried tacking on an additional 10 second delay as a hack/workaround in harbor to let something lagging be happy, but that's made no meaningful difference, as I'm guessing the fundamental issue is on the other side of the XPC boundary from the CLI invocation.

  2. removed their assignment
    on Apr 22, 2026
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