Skip to content

fix(mcp): McpServerController.start/stop race creates a second socket host and leaks the first #1563

Closed

Description

@ZhuchkaTriplesix

Problem

McpServerController.start() (lib/core/mcp/mcp_server_controller.dart:102-124) checks _host != null first, then awaits _version() and host.start(), and assigns _host only after that. Two overlapping calls (startIfEnabled + setEnabled(true), repeated toggle, regenerateToken) create two McpSocketHosts: the first is leaked (never stopped), both write the same endpoint file and the token in the file may not belong to the host that is tracked.

stop() during an in-flight start() sees _host == null, does nothing, and the server comes up afterwards while the setting says disabled.

host.changes.listen is also never cancelled.

Expected

  • Serialize start / stop (single in-flight future or a lock) and assign _host before the first await.
  • Cancel the changes subscription on stop.
  • Test: concurrent start() x2 yields one host; stop() during start() ends stopped.

Activity

  1. added
    bugSomething isn't working
    stabilityTheme parser epic label: stability
    coreCore library logic and services
    P2Medium priority / Parity & Refactoring
    on Oct 13, 2026
  2. ZhuchkaTriplesix commented on Oct 25, 2026

    @ZhuchkaTriplesix
    MemberAuthor

    Fixed on dev by 04714ac: fix(mcp): serialize McpServerController start/stop so overlapping calls cannot leak a socket host (#1563) (#16. It reaches main with the next dev to main merge (closed after checking the code and its tests).

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium priority / Parity & RefactoringbugSomething isn't workingcoreCore library logic and servicesstabilityTheme parser epic label: stability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions