fix(mcp): release tool_list_locked on server removal and probe-block#6143
Merged
Conversation
remove_server and shutdown_all_shared cleared server_tools, server_trust, server_fingerprints, and last_refresh on disconnect but never removed the corresponding tool_list_locked entry, orphaning it for the lifetime of the manager. handle_connect_result (connect_all/connect_oauth_deferred path) also released the lock on connection or list_tools failure but not when the pre-connect probe blocked the connection, unlike the equivalent add_server path (probe_or_cleanup). All four cleanup sites now release tool_list_locked consistently. Closes #6139
bug-ops
enabled auto-merge (squash)
July 12, 2026 15:33
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
remove_serverandshutdown_all_shared(crates/zeph-mcp/src/manager/server.rs) clearedserver_tools,server_trust,server_fingerprints, andlast_refreshon disconnect but never removed the correspondingtool_list_lockedentry — orphaning it for the lifetime of the manager.handle_connect_result(crates/zeph-mcp/src/manager/connect.rs), used by theconnect_all/connect_oauth_deferredpath, released the lock on connection orlist_toolsfailure but not when the pre-connect probe blocked the connection — asymmetric with the equivalentadd_serverpath (probe_or_cleanup), which already cleaned up correctly.tool_list_lockedconsistently.Both gaps are fail-closed and benign (a stale entry only rejects refresh notifications for a server ID with no live connection — a bounded memory leak, not a security regression), found by the adversarial critic and code reviewer while reviewing PR #6138 (fix for #6118).
Closes #6139
Test plan
crates/zeph-mcp/src/manager/tests.rs:remove_server_cleans_up_tool_list_locked_when_client_present,shutdown_all_shared_clears_tool_list_locked,connect_all_does_not_orphan_tool_list_locked_on_connect_failurecargo +nightly fmt --checkcargo clippy --profile ci -p zeph-mcp --all-targets --features "profiling,mock" -- -D warningscargo nextest run --config-file .github/nextest.toml -p zeph-mcp— 534/534 passedRUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps -p zeph-mcpNote: the F2 probe-block line itself (
connect.rshandle_connect_result, "probe blocked" arm) has no direct unit test — the crate's test harness has no mock prober seam to forcerun_probeto returnErrwithout a live MCP connection (confirmed this gap is pre-existing and applies equally to the already-shippedadd_server/probe_or_cleanupreference path). The third regression test exercises the same insert-before-spawn/remove-on-any-failure invariant via the adjacent connection-failure branch instead. Adding true probe-block coverage would require new integration-level test infra and is out of scope for this fix.