Skip to content

Memory leak: MCP OAuth transports not closed on retry or cancellation #9153

Closed

Description

@sauerdaniel

Problem

When MCP OAuth flows are initiated, transports are stored in pendingOAuthTransports Map. These transports are never closed when:

  1. OAuth retry - A new transport is created for the same server, orphaning the previous one
  2. OAuth cancellation - removeAuth() deletes the map entry but doesn't close the transport
  3. 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

Activity

  1. added
    perfIndicates a performance issue or need for optimization
    on Jan 17, 2026
  2. github-actions commented on Jan 17, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

    Both of these issues describe similar symptoms of orphaned MCP server processes and memory leaks that appear directly related to the transport cleanup problems described here.

    Feel free to ignore if none of these address your specific case.

  3. github-actions commented on Mar 27, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 90 days of no activity. If the issue is still relevant please open a new one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

perfIndicates a performance issue or need for optimization

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions