Skip to content

Allow independent MCP backends to launch concurrently - #15006

Merged
lpcox merged 5 commits into
mainfrom
copilot/bugfix-serial-launch-backend
Oct 16, 2026
Merged

lpcox merged 5 commits into
mainfrom
copilot/bugfix-serial-launch-backend

Conversation

Copilot AI commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Parallel backend registration was serialized because the launcher's global mutex remained held during connection startup and MCP initialization. A slow or hung backend could therefore delay every backend behind it.

  • Per-key launch coordination
    • Use singleflight per stateless server and per stateful (server, session) pair.
    • Deduplicate duplicate launches without serializing unrelated backends.
  • Shortened critical sections
    • Protect only cache and runtime-state reads/writes with Launcher.mu.
    • Make recordStart and recordError self-locking.
  • Regression coverage
    • Add a test proving independent HTTP backends begin initialization concurrently.
result, err, _ := l.launchGroup.Do(serverID, func() (any, error) {
    // Launch without holding Launcher.mu.
    conn, err := createConnection()
    if err != nil {
        return nil, err
    }

    l.mu.Lock()
    l.connections[serverID] = conn
    l.mu.Unlock()
    return conn, nil
})

Copilot AI changed the title [WIP] Fix parallel backend launch serialization issue Allow independent MCP backends to launch concurrently Oct 16, 2026
Copilot AI requested a review from lpcox October 16, 2026 15:33
@lpcox
lpcox marked this pull request as ready for review October 16, 2026 15:49
Copilot AI max review requested due to automatic review settings October 16, 2026 15:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Launch completion is not coordinated with shutdown, allowing connections to escape cleanup.

2 open findings
What changed in this PR

Enables independent MCP backends to initialize concurrently while deduplicating launches for each server or session.

Changes:

  • Replace launch-wide locking with per-key singleflight coordination.
  • Limit mutex use to cache and runtime-state updates.
  • Add concurrent HTTP initialization regression coverage.
File Description
internal/​launcher/​launcher.go Coordinate launches per key and shorten critical sections.
internal/​launcher/​launcher_test.go Test concurrent initialization of independent backends.
go.mod Make golang.org/x/sync a direct dependency.

🧠 Review effort: Max


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

logger.LogInfoToServer(serverID, "backend", "Successfully configured HTTP MCP backend: %s", serverID)

l.mu.Lock()
l.connections[serverID] = conn
Comment thread internal/launcher/launcher_test.go Resolved
@lpcox

lpcox commented Oct 16, 2026

Copy link
Copy Markdown
Collaborator

@copilot address review feedback

Copilot AI commented Oct 16, 2026

Copy link
Copy Markdown
Contributor Author

@copilot address review feedback

Addressed in 82be445: shutdown now rejects new launches and closes late connections across all three publication paths. Added blocked-initialization regressions for HTTP and both stdio paths, and fixed timeout cleanup in the concurrency test. Race-enabled launcher tests and make agent-finished passed; CodeQL and secret scans were clean. Optional golangci-lint was unavailable.

@lpcox
lpcox merged commit ae4bfb9 into main Oct 16, 2026
32 checks passed
@lpcox
lpcox deleted the copilot/bugfix-serial-launch-backend branch October 16, 2026 16:30
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.

Parallel backend launch is serialized by the launcher's global write lock, so one hung backend blocks every other server

3 participants