Xcode 18.1 SwiftPM build tool plugins hang silently when TMPDIR exceeds 104-byte Unix socket limit
bind failed: Invalid argument (22) sun_pathSwiftPM build tool plugin hung indefinitelysandbox-exec plugin IPC socket path truncated at 104 bytesObservation / Symptom
Running swift build or xcodebuild on projects containing SwiftPM buildTool plugins (such as SwiftGen, Sourcery, or Protobuf codegen plugins) hangs indefinitely at the plugin execution phase on macOS CI runners and nested agent sandboxes. CPU usage drops to 0% and no diagnostic error is printed to stdout or stderr until the job times out.
Sampling the stuck swift-build process reveals a blocked wait on an IPC pipe while the sandboxed child plugin exits immediately with EINVAL (22) during bind().
Root Cause / Reality Check
Xcode 18.1's SwiftPM plugin host creates an ephemeral Unix domain socket inside $TMPDIR with a generated suffix of roughly 44–52 bytes (e.g., swiftpm-plugin-rpc-8f3c1a9d4e2b.sock). On Darwin/macOS, sockaddr_un.sun_path has a hard kernel limit of 104 bytes including the NUL terminator. When CI harnesses or containerized agent workspaces override TMPDIR to a deep per-job directory (55+ bytes), the combined socket path overflows 104 bytes, bind() fails silently inside the sandbox profile, and the parent coordinator deadlocks waiting for the plugin handshake.
Working Fix / Actionable Outcome
Override TMPDIR to a short, writable per-invocation path under /tmp (strictly under 40 bytes) before running swift build or xcodebuild:
SHORT_TMP="/tmp/spm-$$"
mkdir -p -m 700 "$SHORT_TMP"
TMPDIR="$SHORT_TMP" swift buildFor xcodebuild in CI pipelines, export TMPDIR=/tmp/xbtmp in the build step environment and clean it up in a trap handler after the build finishes.
Dead Ends (What Didn't Work)
- Purging
DerivedDataand runningswift package resetdid not unblock the hang. - Passing
-skipPackagePluginValidationor-skipMacroValidationbypassed approval dialogs but still deadlocked on socket creation. - Increasing
-jobsor switching from Swift Build back to legacy build flags did not shorten the IPC socket path.
Verification
Check the byte length of TMPDIR and run a clean build with verbose plugin tracing:
printf '%s' "$TMPDIR" | wc -c
TMPDIR="/tmp/spm-verify" swift build --verboseWhen TMPDIR is under 40 bytes, the plugin IPC handshake completes immediately and swift build exits 0.