Skip to content

Fix bridge startup on macOS (over-long Unix socket paths) and Windows discover test#259

Merged
jancurn merged 4 commits into
mainfrom
claude/gracious-cray-sNVQH
Jun 3, 2026
Merged

Fix bridge startup on macOS (over-long Unix socket paths) and Windows discover test#259
jancurn merged 4 commits into
mainfrom
claude/gracious-cray-sNVQH

Conversation

@jancurn

@jancurn jancurn commented Jun 3, 2026

Copy link
Copy Markdown
Member

The bridge's Unix socket path is built under the mcpc home dir, so a deep MCPC_HOME_DIR (e.g. macOS /var/folders/... temp dirs, or a long session name) exceeded the OS sockaddr_un limit (104 bytes macOS, 108 Linux) and the bridge crashed on startup — breaking every session-creating E2E test on macOS.

  • getSocketPath() falls back to a short, deterministic temp-dir path when the natural path is too long (CLI and bridge agree on it)
  • Also fixes the Windows connect-discover test that fed an MSYS path to a stdio config

Refs #248

https://claude.ai/code/session_01DJLkPTmAfaayFiwnofxWEv

… discover test

The bridge's Unix domain socket path is built under the mcpc home dir
(~/.mcpc/bridges/<session>.<pid>.sock). When that resolves to a deep path —
notably macOS temp dirs like /var/folders/.../T used by the E2E harness, or a
long session name — it exceeds the OS sockaddr_un.sun_path limit (104 bytes on
macOS/BSD, 108 on Linux). bind()/connect() then fails with ENAMETOOLONG and the
bridge exits during startup, which broke every session-creating E2E test on
macOS (both Node and Bun).

getSocketPath() now falls back to a short, fixed-length path under the OS temp
dir when the preferred path would exceed the limit; the CLI and bridge derive
the same path deterministically. Cleanup (cleanupOrphanedSockets, clean all) and
the bridge's socket-dir creation follow the relocated location.

Also fix the Windows connect-discover E2E test, which wrote an MSYS path
(/d/a/...) into a stdio config; native Windows node misreads it as a relative
path on the current drive. Convert it with to_native_path() like the other
stdio tests.

Refs #248
@jancurn jancurn changed the title Handle Unix socket paths exceeding OS limits Fix bridge startup on macOS (over-long Unix socket paths) and Windows discover test Jun 3, 2026
claude added 3 commits June 3, 2026 12:56
A restarted bridge can reuse a just-killed PID and inherit the stale socket
file left at that PID-based path. startBridge()'s waitForFile() sees the
stale file and returns, so the immediate credential-delivery / health-check
connect hits the dead socket with no retry — making a fast
`mcpc @<session> restart` intermittently fail with
"Failed to connect to bridge: connect ECONNREFUSED" (seen on CI at -p 6).

BridgeClient.connect() now takes an optional retryTimeoutMs that retries
transient errors (ECONNREFUSED/ENOENT) while a freshly spawned bridge is
still (re)creating its socket. Applied to the post-spawn credential, x402
wallet, and health-check connects; other connects still fail fast.

https://claude.ai/code/session_01DJLkPTmAfaayFiwnofxWEv
…econnect)

Follow-up to the rapid-restart ECONNREFUSED fix: rather than passing
retryTimeoutMs at each post-spawn connect, BridgeClient.connect() now retries
transient socket errors (ECONNREFUSED/ENOENT) by default. This removes the
repeated option and also covers SessionClient's reconnect-after-restartBridge
paths, which hit the same stale-socket race but weren't passing the option.

sendBridgeShutdown opts out with retryTimeoutMs: 0 — it targets an
already-running bridge and force-kills if unreachable, so retrying makes no sense.

https://claude.ai/code/session_01DJLkPTmAfaayFiwnofxWEv
Replace the fixed 75ms retry sleep with a base (50ms) plus random jitter
(0-50ms) so many clients retrying at once (e.g. parallel bridges in tests)
don't wake on the same cadence and hammer their sockets together. Average
delay is unchanged (~75ms).

https://claude.ai/code/session_01DJLkPTmAfaayFiwnofxWEv
@jancurn jancurn merged commit b02a878 into main Jun 3, 2026
6 checks passed
@jancurn jancurn deleted the claude/gracious-cray-sNVQH branch June 3, 2026 15:53
jancurn added a commit that referenced this pull request Jun 3, 2026
On Windows, `mcpc connect` wrapped discovered/invalid config paths in
double quotes (`"D:\...\mcp.json"`) because `formatPath` treated the
backslash as shell-unsafe. Backslash is the path separator on Windows
(safe unquoted in cmd/PowerShell) but a shell escape character on POSIX,
so it's now treated as safe only on Windows. This also fixes the
`connect-discover` e2e test that was failing on Windows.

- Plain Windows paths (`C:\Users\foo\mcp.json`) render unquoted; paths
with spaces stay quoted
- POSIX output is unchanged
- Added `formatPath` unit tests for both platforms

Refs #259

https://claude.ai/code/session_01UNivY6TKwgTnNX4xB6n61t

Co-authored-by: Claude <noreply@anthropic.com>
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.

3 participants