fix: catch BaseException in MCP shutdown guards to suppress double-Ctrl+C traceback - #39479
Merged
Conversation
Contributor
🔎 Lint report:
|
tonydwb
approved these changes
Jun 5, 2026
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
Small but effective shutdown robustness fix. Replacing Exception with BaseException is the right move here: cleanup paths should not let KeyboardInterrupt/SystemExit break shutdown.
✅ Looks Good
- Change is surgical and fully aligned with intended behavior.
- Scope is limited to MCP shutdown + CLI cleanup.
- No observable side effects on normal execution paths.
💡 Suggestions
- Consider documenting this non-obvious choice inline (one comment) so future readers don’t revert it back to
Exceptionduring cleanup refactors.
Reviewed by Hermes Agent
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
A second Ctrl+C during MCP shutdown now exits cleanly instead of printing a
KeyboardInterrupttraceback.The CLI's
_signal_handler_qraisesKeyboardInterrupt(aBaseException, notException). The two best-effort teardown guards on the shutdown path caught onlyException, so a second interrupt during the up-to-15sfuture.result(timeout=15)wait escaped cleanup and surfaced as an unhandled traceback.Salvage of #39453 by @HeLLGURD onto current
main(the original branch was stale — its diff also showed a_branched_fromblock already present on main; that phantom chunk drops out on cherry-pick). Closes #39367.Changes
cli.py_run_cleanup():except Exception→except BaseExceptiontools/mcp_tool.pyshutdown_mcp_servers():except Exception→except BaseExceptionBoth guards are pure best-effort teardown (
pass/ log-and-continue), so the wider catch only lets cleanup finish and the process exit without a traceback.Validation
E2E (real source from worktree):
except Exception(old)except BaseException(new)Both files compile clean.
Credit: @HeLLGURD (commits cherry-picked with authorship preserved).
Infographic