Skip to content

Memory leak: MCP clients not closed before reassignment #8257

Closed

Description

@sauerdaniel

Description

When MCP clients are reassigned in MCP.add() or during OAuth finishAuth(), the existing client at that key is silently overwritten without being closed first.

Impact

  • Open connections/sockets are orphaned
  • Active event listeners accumulate
  • Resources are never released
  • Contributes to memory growth in long-running sessions

Location

packages/opencode/src/mcp/index.ts - two locations where s.clients[name] = result.mcpClient overwrites existing clients

Reproduction

  1. Connect to an MCP server
  2. Reconnect or complete OAuth flow
  3. Previous client is leaked

Related

Part of #3013 (general memory issues)
Related to #7261 (MCP orphan processes)

Activity

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

    @github-actions
    Contributor

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

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

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