fix: avoid event-loop stalls from synchronous tmux/ps calls#100
Merged
Conversation
The stats collector (~2s) and mouse-mode sync (5s) ran execSync (pgrep/ps/ list-panes, 5s timeout each) per session on the server's single thread, blocking the event loop. With several sessions or a momentarily slow tmux this froze port 3000 for seconds-to-tens-of-seconds while the process stayed alive and other ports were unaffected — self-healing, so it never restarted and the 60s loopback healthcheck missed it. Convert these hot-path calls to execAsync. Also add an always-on event-loop lag monitor (utils/event-loop-monitor.ts) that logs stalls >=1s to the web log, so this otherwise-invisible class of incident leaves a quantified, timestamped trace.
Owner
|
Thank you as always for contributing, @TeigenZhang! 🙏 Reviewed and verified locally on the PR branch:
Great catch on the blocking |
3 tasks
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.
Summary
The session manager called
execSyncfor tmux mouse-mode andlist-panesqueries on the main thread. Under load (many sessions / agent panes) these synchronous spawns block Node's event loop, stalling SSE broadcasts and PTY I/O.This converts those calls to async (
execAsync) and adds a lightweightevent-loop-monitorutility that samples loop-delay and logs when a stall threshold is exceeded, making future regressions observable.Changes
tmux-manager.ts:enableMouseMode/disableMouseMode/listPanesnow useexecAsyncinstead ofexecSyncutils/event-loop-monitor.ts(new): periodic event-loop delay samplerutils/index.ts: export the monitorserver.ts: start the monitor on bootTest plan
tsc --noEmitpasses