Skip to content

Commit 4aa0fd8

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: prevent warning logs when cancelling MCP session runner task
PiperOrigin-RevId: 943500722
1 parent 1263ed6 commit 4aa0fd8

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/google/adk/tools/mcp_tool/session_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,8 @@ async def _run(self):
347347

348348
# Wait for close signal - the session remains valid while we wait
349349
await self._close_event.wait()
350-
except BaseException as e:
351-
logger.warning(f'Error on session runner task: {e}')
350+
except Exception as e:
351+
logger.warning('Error on session runner task: %s', e)
352352
raise
353353
finally:
354354
self._ready_event.set()

tests/unittests/tools/mcp_tool/test_session_context.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,14 @@ async def test_close_handles_cancelled_error(self):
609609

610610
mock_session = MockClientSession()
611611

612-
with patch(
613-
'google.adk.tools.mcp_tool.session_context.ClientSession'
614-
) as mock_session_class:
612+
with (
613+
patch(
614+
'google.adk.tools.mcp_tool.session_context.ClientSession'
615+
) as mock_session_class,
616+
patch(
617+
'google.adk.tools.mcp_tool.session_context.logger'
618+
) as mock_logger,
619+
):
615620
mock_session_class.return_value = mock_session
616621

617622
await session_context.start()
@@ -626,6 +631,9 @@ async def test_close_handles_cancelled_error(self):
626631
# Should not raise exception
627632
assert session_context._close_event.is_set()
628633

634+
# Verify no warning logs were generated
635+
mock_logger.warning.assert_not_called()
636+
629637
@pytest.mark.asyncio
630638
async def test_close_handles_exception_during_cleanup(self):
631639
"""Test that close() handles exceptions during cleanup gracefully."""

0 commit comments

Comments
 (0)