Skip to content

feat(net): add SocketShortener for Unix socket sun_path limit#398

Merged
DorianZheng merged 2 commits into
mainfrom
feat/socket-path-shortener
Mar 20, 2026
Merged

feat(net): add SocketShortener for Unix socket sun_path limit#398
DorianZheng merged 2 commits into
mainfrom
feat/socket-path-shortener

Conversation

@DorianZheng

Copy link
Copy Markdown
Member

Summary

  • Add SocketShortener type that creates short /tmp/bl_{id} symlinks to work around the Unix socket sun_path limit (104 bytes on macOS, 108 on Linux)
  • Kernel resolves symlinks during VFS lookup AFTER the sun_path length check — same pattern used by Open vSwitch (shorten_name_via_symlink())
  • Socket files physically remain in ~/.boxlite/boxes/{id}/sockets/ — symlink is just a short alias
  • SocketShortener::new() returns None when paths already fit — no symlink created unnecessarily
  • Includes cleanup_stale_symlinks() for dead symlink removal on runtime startup
  • Auto-cleanup on Drop

Test plan

  • 18 unit tests pass (cargo test -p boxlite --lib net::socket_path)
  • Clippy clean (cargo clippy -p boxlite --lib -- -D warnings)
  • Tests cover: symlink creation, path length validation, stale symlink replacement, refusal to overwrite non-symlinks, cleanup/Drop, resolve_socket_path, stale cleanup, and kernel bind/connect-through-symlink validation
  • Integration: shim-side chdir and vmm_spawn wiring (follow-up PR)

Unix domain sockets have a sun_path limit of 104 bytes (macOS) / 108
bytes (Linux). Long BOXLITE_HOME paths can exceed this limit.

Add SocketShortener that creates a short symlink in /tmp (e.g.,
/tmp/bl_{short_id}) pointing to the real sockets directory. The kernel
resolves symlinks during VFS lookup AFTER the sun_path length check,
so the short path satisfies the buffer constraint while socket files
physically remain in ~/.boxlite/. This is the same pattern used by
Open vSwitch (shorten_name_via_symlink in socket-util-unix.c).

Includes 18 unit tests covering symlink creation, cleanup, stale
symlink removal, and kernel bind/connect-through-symlink validation.
@DorianZheng DorianZheng merged commit 3f33032 into main Mar 20, 2026
18 checks passed
@DorianZheng DorianZheng deleted the feat/socket-path-shortener branch March 20, 2026 07:36
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.

1 participant