Skip to content

fix(mcp): clean up subprocess listeners on OAuth browser open#1346

Open
walker83 wants to merge 1 commit into
XiaomiMiMo:mainfrom
walker83:fix/mcp-subprocess-cleanup
Open

fix(mcp): clean up subprocess listeners on OAuth browser open#1346
walker83 wants to merge 1 commit into
XiaomiMiMo:mainfrom
walker83:fix/mcp-subprocess-cleanup

Conversation

@walker83

Copy link
Copy Markdown

Summary

Clean up subprocess.on("error") and subprocess.on("exit") listeners after they fire, and on the success path.

Problem

When the 500ms timer fires (success path), resume(Effect.void) is called but the error and exit listeners on the subprocess are never removed. The closures captured by these listeners prevent GC of the subprocess object and surrounding scope.

Fix

Extract a common cleanup() helper that:

  1. Clears the timer
  2. Removes both listeners via subprocess.off()
  3. Then calls resume()

This ensures all three paths (timer, error, exit) properly clean up.

Changes

  • packages/opencode/src/mcp/index.ts: add cleanup helper for subprocess listeners

Checklist

  • Code follows project style guidelines
  • All exit paths properly clean up

Remove subprocess 'error' and 'exit' listeners after they fire, and
on the success (timer) path. Previously all three paths left the
listeners registered, leaking closures indefinitely.
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