fix: bound captured mihomo output#12
Draft
lianglunping wants to merge 1 commit into
Draft
Conversation
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
This PR bounds the amount of mihomo stdout/stderr retained by the Electron main process.
The current code appends every mihomo output chunk to long-lived strings:
On a long-running session with regular mihomo connection logs, these strings can grow without limit and eventually trigger a main-process exception such as:
Issues appear to be disabled for this repository, so I am including the bug report details in this PR body.
Changes
appendBoundedOutputhelper that keeps only the latest captured output.mihomo-service.js.node:testcoverage for the buffer behavior.npm testscript for the new tests.Why
The captured stdout/stderr is used only for startup failure diagnostics, such as extracting fatal errors or showing the last few lines. Keeping the complete lifetime output is unnecessary and can crash the Electron main process after enough log output accumulates.
The helper keeps the newest output, preserving the existing diagnostics behavior that reports recent output while preventing unbounded string growth.
Validation
node --test test/bounded-output-buffer.test.jspasses.npm testpasses: 3 tests, 3 passing.node --check electron/main-process/bounded-output-buffer.jspasses.node --check electron/main-process/mihomo-service.jspasses.node -e "require('./package.json')"passes.npm run buildpasses.npm run lintcould not run a real lint pass because this repository currently has no ESLint config;next lintopens the interactive ESLint setup prompt and exits instead of linting.