Skip to content

fix: bound captured mihomo output#12

Draft
lianglunping wants to merge 1 commit into
GtxFury:mainfrom
lianglunping:codex/bound-mihomo-output-buffer
Draft

fix: bound captured mihomo output#12
lianglunping wants to merge 1 commit into
GtxFury:mainfrom
lianglunping:codex/bound-mihomo-output-buffer

Conversation

@lianglunping

Copy link
Copy Markdown

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:

stdoutOutput += logContent;
stderrOutput += errorText;

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:

RangeError: Invalid string length
at Socket.<anonymous> (.../electron/main-process/mihomo-service.js:1203:25)

Issues appear to be disabled for this repository, so I am including the bug report details in this PR body.

Changes

  • Add a small appendBoundedOutput helper that keeps only the latest captured output.
  • Use it for both mihomo stdout and stderr capture in mihomo-service.js.
  • Add Node's built-in node:test coverage for the buffer behavior.
  • Add an npm test script 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.js passes.
  • npm test passes: 3 tests, 3 passing.
  • node --check electron/main-process/bounded-output-buffer.js passes.
  • node --check electron/main-process/mihomo-service.js passes.
  • node -e "require('./package.json')" passes.
  • npm run build passes.

npm run lint could not run a real lint pass because this repository currently has no ESLint config; next lint opens the interactive ESLint setup prompt and exits instead of linting.

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