fix: Fix MCPToolset crashing with anyio.BrokenResourceError

Add error handling for broken resource error so that it retries. Fixes https://github.com/google/adk-python/issues/2769.

Co-authored-by: Kathy Wu <wukathy@google.com>
PiperOrigin-RevId: 829146121
This commit is contained in:
Kathy Wu
2025-11-06 16:12:49 -08:00
committed by Copybara-Service
parent c0be1df052
commit 8e0648df23
@@ -126,9 +126,10 @@ def retry_on_closed_resource(func):
async def wrapper(self, *args, **kwargs): async def wrapper(self, *args, **kwargs):
try: try:
return await func(self, *args, **kwargs) return await func(self, *args, **kwargs)
except anyio.ClosedResourceError: except (anyio.ClosedResourceError, anyio.BrokenResourceError):
# Simply retry the function - create_session will handle # If the session connection is closed or unusable, we will retry the
# detecting and replacing disconnected sessions # function to reconnect to the server. create_session will handle
# detecting and replacing disconnected sessions.
logger.info('Retrying %s due to closed resource', func.__name__) logger.info('Retrying %s due to closed resource', func.__name__)
return await func(self, *args, **kwargs) return await func(self, *args, **kwargs)