perf(tmux): skip dead sockets so list_panes doesn't spawn tmux per orphan#56
Merged
Conversation
…n tmux spawns `list_panes()` / the scanner enumerate every socket file under `/tmp/tmux-<uid>` and spawn a `tmux -S <sock> list-panes` per file. tmux only unlinks a server's own socket on clean shutdown, so servers killed abnormally (test timeouts, SIGKILL, parent shell dying) leave orphan socket files, and on a host without a working /tmp reaper (e.g. a container where systemd-tmpfiles never runs) they accumulate without bound — hundreds were seen in the wild. Each orphan cost a full tmux process spawn (~2ms) on every scan, so a few hundred turned into ~0.5s, which showed up as a visibly late first paint in `muxa watch` (the priming refresh waits on list_panes). enumerate_sockets now drops dead sockets with a cheap connect() probe before any caller spawns tmux: a live server accepts, a stale file refuses instantly with ECONNREFUSED (no blocking, no spawn). Other connect errors keep the socket so we never hide one we merely failed to probe. Measured locally: `muxa status` 485ms -> ~20ms with ~220 orphan sockets present. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
muxa watchshowed its list ~1s late on first paint. Root cause was not the watch client or streaming — it wascrate::tmux::list_panes()(called by the watch's priming refresh,muxa status, and the daemon scanner) enumerating every socket file under/tmp/tmux-<uid>and spawning atmux -S <sock> list-panesfor each.tmux only unlinks a server's own socket on clean shutdown, so servers killed abnormally (test timeouts, SIGKILL, parent shell dying) leave orphan socket files. On a host without a working
/tmpreaper (a container wheresystemd-tmpfilesnever runs) they accumulate without bound — ~220 orphans were observed locally. Each orphan cost a fulltmuxprocess spawn (~2ms) on every scan → ~0.5s, surfacing as the late first paint.Fix
enumerate_sockets()now drops dead sockets with a cheapconnect()probe before any caller spawns tmux: a live server accepts, a stale file refuses instantly withECONNREFUSED(no blocking, no spawn). Other connect errors keep the socket so we never hide one we merely failed to probe. Benefits every caller (list_panes, scanner, daemon reconciler/discovery).Measured
muxa status(shares thelist_panespath): 485ms → ~20ms with ~220 orphan sockets present.Test
New unit test
socket_is_live_distinguishes_listening_from_orphan(bound listener = live; bind-then-drop orphan = dead; missing = dead).cargo fmt/clippy -D warnings/test -p muxagreen.🤖 Generated with Claude Code