Skip to content

fix(mcp): release tool_list_locked on server removal and probe-block#6143

Merged
bug-ops merged 2 commits into
mainfrom
fix/6139-tool-list-locked-orphan-cleanup
Jul 12, 2026
Merged

fix(mcp): release tool_list_locked on server removal and probe-block#6143
bug-ops merged 2 commits into
mainfrom
fix/6139-tool-list-locked-orphan-cleanup

Conversation

@bug-ops

@bug-ops bug-ops commented Jul 12, 2026

Copy link
Copy Markdown
Owner

Summary

  • remove_server and shutdown_all_shared (crates/zeph-mcp/src/manager/server.rs) 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 (crates/zeph-mcp/src/manager/connect.rs), used by the connect_all/connect_oauth_deferred path, released the lock on connection or list_tools failure but not when the pre-connect probe blocked the connection — asymmetric with the equivalent add_server path (probe_or_cleanup), which already cleaned up correctly.
  • All four cleanup sites now release tool_list_locked consistently.

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

  • Added 3 regression tests in 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_failure
  • cargo +nightly fmt --check
  • cargo clippy --profile ci -p zeph-mcp --all-targets --features "profiling,mock" -- -D warnings
  • cargo nextest run --config-file .github/nextest.toml -p zeph-mcp — 534/534 passed
  • RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--deny rustdoc::broken_intra_doc_links" cargo doc --no-deps -p zeph-mcp

Note: the F2 probe-block line itself (connect.rs handle_connect_result, "probe blocked" arm) has no direct unit test — the crate's test harness has no mock prober seam to force run_probe to return Err without a live MCP connection (confirmed this gap is pre-existing and applies equally to the already-shipped add_server/probe_or_cleanup reference 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.

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
@github-actions github-actions Bot added bug Something isn't working size/M Medium PR (51-200 lines) documentation Improvements or additions to documentation rust Rust code changes labels Jul 12, 2026
@bug-ops
bug-ops enabled auto-merge (squash) July 12, 2026 15:33
@bug-ops
bug-ops merged commit 58e59be into main Jul 12, 2026
43 checks passed
@bug-ops
bug-ops deleted the fix/6139-tool-list-locked-orphan-cleanup branch July 12, 2026 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation rust Rust code changes size/M Medium PR (51-200 lines)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tool_list_locked entries orphaned on server removal / probe-block in connect path

1 participant