fix: Update the retry_on_closed_resource decorator to retry on all errors

Retrying only on closed_resource error is not enough to be reliable for production environments due to the other network errors that may occur -- remote protocol error, read timeout, etc. We will update this to retry on all errors. Since it is only a one-time retry, it should not affect latency significantly. Fixes https://github.com/google/adk-python/issues/2561.

PiperOrigin-RevId: 831153803
This commit is contained in:
Google Team Member
2025-11-11 18:44:18 -08:00
committed by Copybara-Service
parent 999af55880
commit 3674fbbe8f
4 changed files with 17 additions and 17 deletions
@@ -32,7 +32,7 @@ pytestmark = pytest.mark.skipif(
# Import dependencies with version checking
try:
from google.adk.tools.mcp_tool.mcp_session_manager import MCPSessionManager
from google.adk.tools.mcp_tool.mcp_session_manager import retry_on_errors
from google.adk.tools.mcp_tool.mcp_session_manager import retry_on_closed_resource
from google.adk.tools.mcp_tool.mcp_session_manager import SseConnectionParams
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from google.adk.tools.mcp_tool.mcp_session_manager import StreamableHTTPConnectionParams
@@ -44,7 +44,7 @@ except ImportError as e:
pass
MCPSessionManager = DummyClass
retry_on_errors = lambda x: x
retry_on_closed_resource = lambda x: x
SseConnectionParams = DummyClass
StdioConnectionParams = DummyClass
StreamableHTTPConnectionParams = DummyClass
@@ -375,12 +375,12 @@ class TestMCPSessionManager:
assert "Close error 1" in error_output
def test_retry_on_errors_decorator():
"""Test the retry_on_errors decorator."""
def test_retry_on_closed_resource_decorator():
"""Test the retry_on_closed_resource decorator."""
call_count = 0
@retry_on_errors
@retry_on_closed_resource
async def mock_function(self):
nonlocal call_count
call_count += 1