Skip to content

[Bug]: Head-of-line blocking in BidirectionalRelay causes permanent hang under concurrent vsock proxy load #712

@mlsad3

Description

@mlsad3

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

  1. Run an application that opens many simultaneous socket connections through the UnixSocketRelay vsock proxy (e.g., multiple concurrent operations that stress the proxy heavily)
  2. Generate enough concurrent traffic that at least one destination file descriptor's write buffer fills up
  3. Attempt any new operation through the proxy (e.g., a simple status check)

The hang is reliably reproducible by launching 5+ concurrent container operations simultaneously. Once triggered, the proxy never recovers — all existing and new connections hang indefinitely until the process is restarted.

Current behavior

The entire vsock proxy becomes permanently unresponsive. All connections — including completely unrelated new ones — hang indefinitely. The process must be fully restarted to recover.

Root cause: BidirectionalRelay uses synchronous write() calls on a shared serial DispatchQueue (com.apple.containerization.socket-relay). When a destination fd's buffer fills (remote end temporarily busy), the write() blocks the serial queue. Since all relay connections share this queue, a single blocked write freezes every connection.

Secondary issue: When a relay is torn down while under backpressure (read source suspended), stop() calls cancel() on the suspended DispatchSourceRead. GCD does not deliver cancel handlers on suspended dispatch sources, so file descriptors leak and waitForCompletion() never resolves.

Expected behavior

When one connection's destination buffer is full, only that connection should stall. All other relay connections should continue operating normally. When backpressure clears, the stalled connection should resume without intervention.

Environment

- OS: macOS 26.x (Tahoe)
- Xcode: 26.4
- Swift: 6.3

Relevant log output

N/A

Code of Conduct

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

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