Shut down superseded MCP managers on refresh (#29608)

## Summary

MCP refresh replaced the published connection manager without shutting
down the manager it superseded. If another task retained that old
manager, its stdio MCP processes stayed alive and accumulated across
refreshes.

Atomically swap in the refreshed manager, then explicitly shut down the
exact manager returned by the swap. Add a process-level regression test
that retains the old manager during refresh and verifies its stdio
process exits while the replacement remains available.

## Context

Explicit cleanup was lost when manager publication moved to `ArcSwap`.
Dropping the old manager is not a reliable shutdown boundary because
active callers can retain its `Arc` and underlying client process
handles.
This commit is contained in:
jif
2026-06-23 18:29:27 +01:00
committed by GitHub
Unverified
parent 9fe689783d
commit 8751fd3fcb
5 changed files with 195 additions and 4 deletions
+4 -2
View File
@@ -371,9 +371,11 @@ impl Session {
let current_manager = self.services.mcp_connection_manager.load_full();
refreshed_manager.set_elicitations_auto_deny(current_manager.elicitations_auto_deny());
}
self.services
let superseded_manager = self
.services
.mcp_connection_manager
.store(Arc::new(refreshed_manager));
.swap(Arc::new(refreshed_manager));
superseded_manager.shutdown().await;
}
pub(crate) async fn refresh_mcp_servers_if_requested(