opencode
opencode copied to clipboard
Memory leak: MCP OAuth transports not closed on retry or cancellation
Problem
When MCP OAuth flows are initiated, transports are stored in pendingOAuthTransports Map. These transports are never closed when:
- OAuth retry - A new transport is created for the same server, orphaning the previous one
-
OAuth cancellation -
removeAuth()deletes the map entry but doesn't close the transport - OAuth timeout - Incomplete flows leave open transports
Additionally, when the main OpenCode process terminates, spawned MCP server processes may continue running as orphans.
Code Location
packages/opencode/src/mcp/index.ts
Impact
- Open connections accumulate over OAuth retries
- Orphaned MCP server processes after OpenCode exits
- Memory growth in long-running sessions
Relates to #5363
Expected Behavior
- Old transports should be closed before creating new ones
-
removeAuth()should close transport before deletion - Process exit should clean up all MCP clients