Skip to content

fix(daemon): keep the socket path under the AF_UNIX limit - #267

Merged
georgeh0 merged 1 commit into
cocoindex-io:mainfrom
junzh0u:fix/daemon-socket-path
Aug 5, 2026
Merged

fix(daemon): keep the socket path under the AF_UNIX limit#267
georgeh0 merged 1 commit into
cocoindex-io:mainfrom
junzh0u:fix/daemon-socket-path

Conversation

@junzh0u

@junzh0u junzh0u commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

Summary

The daemon socket lives at <runtime dir>/daemon.sock, but a unix socket address is capped at 104 bytes on macOS/BSD (108 on Linux) where ordinary files get ~1024. A deep runtime dir — long $HOME, sandbox, container, CI workspace — makes bind() fail with OSError: AF_UNIX path too long, which reaches the user as "Daemon process exited before it became ready" and reads like a broken install. A home directory ~72 bytes deep is enough, since /.cocoindex_code/daemon.sock adds 28.

When the natural path is over the limit, fall back to a short temp-dir address named ccc-<uid>-<hash of runtime dir>.sock — hashed so daemons differing only by COCOINDEX_CODE_RUNTIME_DIR keep distinct sockets, uid because /tmp is shared on Linux. Below the limit, nothing changes.

Validation

Real output, using the runtime dir from a sandbox that hit this:

sun_path limit (macOS)  : 104
natural socket path     : /private/var/folders/nf/0rxqtdrs2hz89392pfrb31400000gn/T/claude-eval-y1pCn8/home/.cocoindex_code/daemon.sock
  length                : 108 bytes  -> OVER LIMIT (bind fails)
daemon_socket_path()    : /var/folders/nf/0rxqtdrs2hz89392pfrb31400000gn/T/ccc-501-a32f3a083724.sock
  length                : 74 bytes  -> bindable

Reproduce the original failure on macOS — fails before, starts after:

DEEP="$TMPDIR/$(python3 -c 'print("d"*90)')" && mkdir -p "$DEEP"
COCOINDEX_CODE_RUNTIME_DIR="$DEEP" ccc status

Worth knowing on review: the limit applies to the string passed to bind(), not the path after symlink resolution (verified directly — a 102-byte /var/... address binds even though it resolves to 110 under /private). So the check measures the unresolved string.

  • uv run pytest — 298 passed, 3 new (short path unchanged, fallback under the limit, two over-long runtime dirs don't collide)
  • uv run prek run --all-files — passed

Operational impact

None — no migration, no config change, no new setting. A daemon already running keeps its socket, since it was under the limit or it would not have started. Windows named pipes are unaffected; that branch only shares the new hash helper.

Independent of #243 (daemon startup races) — different files, different failure mode.

🤖 Generated with Claude Code

The socket address is <runtime dir>/daemon.sock, but sun_path caps a
unix socket at 104 bytes on macOS (108 on Linux) where ordinary files
get PATH_MAX. A deep $HOME -- a sandbox, a container, a CI runner --
pushes past it, and bind() fails with "AF_UNIX path too long" surfacing
as "Daemon process exited before it became ready", which reads like a
broken install rather than a path-length problem.

Fall back to a short temp-dir address keyed by a hash of the runtime
dir when the natural path is too long, so distinct runtime dirs keep
distinct sockets; the uid is in the name because /tmp is shared on
Linux. Client and daemon both resolve through daemon_socket_path(), so
they agree either way.

Found by an eval agent working in a sandbox with a long $HOME; it lost
several turns diagnosing the daemon before deducing the
COCOINDEX_CODE_RUNTIME_DIR workaround. Note pytest's own tmp_path is
~118 bytes on macOS, so the overflow is not an exotic case.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LksW8LnigLAiFnrgLauW8M

@georgeh0 georgeh0 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix!

@junzh0u
junzh0u marked this pull request as ready for review August 5, 2026 04:21
@badmonster0

Copy link
Copy Markdown
Member

great fix, thanks @junzh0u !

@georgeh0
georgeh0 merged commit 68298cc into cocoindex-io:main Aug 5, 2026
4 checks passed
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