googleapis / googleapis/mcp-toolbox-sdk-python

fix(core): close managed session after cancelled initialization

Aperta
#744 1 commento 0 reazioni 1 assegnatario Rivendicata da @anubhav756 Vedi su GitHub
priority: p2 type: bug
Lingua principale
Python
Stelle
192
Fork
60
Merge medio
5g 20m
PR unite (30g)
13

Descrizione

## Summary

When an MCP transport initialization task is cancelled, `_McpHttpTransportBase.close()` propagates `asyncio.CancelledError` before closing its internally managed `aiohttp.ClientSession`.

## Environment

- SDK revision: `88cc7959d9c7ebc1d92dedeae90e56fb10d2a943` (`upstream/main`)
- Python: 3.13.5
- Toolbox server: not required; the failure occurs in local transport cleanup

## Current behavior

1. Create a core MCP transport with its internally managed session.
2. Assign or reach a cancelled initialization task.
3. Call `await transport.close()`.

`close()` raises `CancelledError`, and `transport._session.closed` remains `False`.

## Expected behavior

Explicitly closing the transport should close its internally managed session even when initialization was cancelled, just as it already does for other initialization failures. Externally supplied sessions should remain caller-owned.

## Root cause

`asyncio.CancelledError` inherits from `BaseException`, so the existing `except Exception` cleanup path does not catch it and session cleanup is skipped.

## Proposed scope

Handle the cancelled cached initialization task inside `close()` and add focused regression coverage. Initialization retry and request-cancellation semantics are out of scope.

## AI assistance

OpenAI Codex assisted with repository auditing, reproduction, and test preparation.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.