Python: Fix MCP plugin hang when initialization fails #13414 #13437
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
Issue No : #13414
This PR fixes a deadlock in the Python MCP plugins where connection failures during background initialization could cause connect() to hang indefinitely.
Problem
connect() waits on a readiness future that was never resolved when _inner_connect() failed during session initialization (e.g. HTTP 401/403). The exception was trapped in the background task and never propagated.
Fix
Ensure _inner_connect() always resolves the readiness future with an exception when initialization fails, allowing the error to surface immediately and preventing hangs.
Scope
No changes to MCP protocol behavior
No changes to tool loading or normalization
Minimal diff, focused solely on error propagation
Notes
Some MCP unit tests are environment-dependent and may fail locally, including on main. This PR does not modify test behavior.