MemOS icon indicating copy to clipboard operation
MemOS copied to clipboard

fix(memos-local-plugin): close all pipe fds in bridge_client to prevent process leaks

Open rayraiser opened this issue 6 months ago • 1 comments

Problem

The close() method in bridge_client.py only closed stdin, leaving stdout and stderr pipe 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() called self._proc.stdin.close() but never closed stdout/stderr
  • The Node bridge process stayed alive, holding the pipe open
  • New sessions spawned new bridge processes, each leaking

Fix

Close all pipe fds (stdin, stdout, stderr) in close(), then wait() up to 2s for graceful exit before terminate().

Impact

  • Bridge processes now exit cleanly on session end
  • No orphan process accumulation
  • Viewer will restart on new session (acceptable trade-off)

Files Changed

  • apps/memos-local-plugin/adapters/hermes/memos_provider/bridge_client.py

rayraiser avatar May 10 '26 10:05 rayraiser

This PR has been automatically marked as stale due to inactivity.

github-actions[bot] avatar Jun 10 '26 06:06 github-actions[bot]

Thanks! On current main the premise no longer holds: close() no longer relies on stdin/stdout/stderr reaching EOF for the child to exit — it escalates to SIGTERM and then SIGKILL, and the #1910 singleton registry reaps the previous client. The fd-leak-driven orphan accumulation this fixes is therefore already prevented.

Closing as superseded; reopen if you can still reproduce on latest main.

shinetata avatar Jul 14 '26 13:07 shinetata