GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — Memory Leak: Orphaned processes when terminal closes without explicit exit · Issue #10563 · anomalyco/opencode Closed Labels perfIndicates a performance issue or need for optimization DescriptionProblemWhen users close terminal windows without explicitly exiting OpenCode (Ctrl+C), the OpenCode process and all its MCP child processes become orphaned (parent becomes launchd/PID 1) and continue consuming memory indefinitely. Evidence from a real user system:All 38 orphaned processes had Root CauseOpenCode doesn't properly handle terminal closure signals (SIGHUP) or doesn't propagate termination to MCP child processes. Proposed SolutionOption 1: Fix in OpenCode Core (Recommended)Add proper signal handling in the main process: // Example for Go codebase func setupSignalHandling() { sigs := make(chan os.Signal, 1) signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM, syscall.SIGHUP, syscall.SIGQUIT) go func() { <-sigs // Kill all child processes (MCP servers) killChildProcesses() os.Exit(0) }() } func killChildProcesses() { // Get process group and kill all children pgid, err := syscall.Getpgid(os.Getpid()) if err == nil { syscall.Kill(-pgid, syscall.SIGTERM) time.Sleep(500 * time.Millisecond) syscall.Kill(-pgid, syscall.SIGKILL) } } Option 2: Wrapper Script Workaround (User-side)For users experiencing this issue now, a wrapper script can help: #!/bin/bash # ~/.local/bin/opencode-wrapper OPENCODE_BIN="/opt/homebrew/bin/opencode" # or wherever opencode is installed cleanup() { get_descendants() { local parent=$1 local children=$(pgrep -P $parent 2>/dev/null) for child in $children; do echo $child get_descendants $child done } local all_children=$(get_descendants $$) if [ -n "$all_children" ]; then echo $all_children | xargs kill 2>/dev/null sleep 0.5 echo $all_children | xargs kill -9 2>/dev/null fi } trap cleanup EXIT INT TERM HUP QUIT exec "$OPENCODE_BIN" "$@" Installation: chmod +x ~/.local/bin/opencode-wrapper echo 'alias opencode="~/.local/bin/opencode-wrapper"' >> ~/.zshrc source ~/.zshrc Expected Behavior
Environment
Impact
Reacted by Jonathan Hult, Dollan, Mikhail Levchenko and Zhuoyuan Hao (Larry Hao / 郝卓远) Activity
MetadataMetadataAssigneesLabelsperfIndicates a performance issue or need for optimization TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |