fix(memos-local-plugin): close all pipe fds in bridge_client to prevent process leaks#1676
Open
rayraiser wants to merge 2 commits intoMemTensor:mainfrom
Open
fix(memos-local-plugin): close all pipe fds in bridge_client to prevent process leaks#1676rayraiser wants to merge 2 commits intoMemTensor:mainfrom
rayraiser wants to merge 2 commits intoMemTensor:mainfrom
Conversation
…nagement
Fix three interrelated issues causing bridge process leaks:
1. bridge_client.py: Restore original close() behavior - only close stdin,
don't terminate the daemon. This allows the bridge process to survive
as a daemon across client reconnects.
2. __init__.py: Add daemon detection before spawn. Check if port 18800
is already bound and healthy before spawning a new bridge. Reuse
existing daemon instead of blind spawn -> close -> spawn loop.
3. daemon_manager.py: Add bridge lifecycle guard with:
- _is_port_bound() / _bridge_health_check() for daemon detection
- Process age detection (10s grace period) to avoid killing
initializing bridges
- _cleanup_zombie_bridges() to kill orphaned processes
- Port-owner tracking to keep only the process that actually binds 18800
Result: Bridge process count stabilizes at 2 (parent tsx + child node)
instead of growing to 6+ with continuous zombie spawn cycles.
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
The
close()method inbridge_client.pyonly closedstdin, leavingstdoutandstderrpipe file descriptors open. Because the bridge process (node tsx) only exits when stdin reaches EOF and there are no open pipe references, this caused bridge processes to accumulate as orphans (e.g., 78+ processes per session).Root Cause
close()calledself._proc.stdin.close()but never closedstdout/stderrFix
Close all pipe fds (
stdin,stdout,stderr) inclose(), thenwait()up to 2s for graceful exit beforeterminate().Impact
Files Changed
apps/memos-local-plugin/adapters/hermes/memos_provider/bridge_client.py