Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/google/adk/integrations/daytona/_daytona_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ async def close(self) -> None:
if self._sandbox is not None:
await self._sandbox.delete()
self._sandbox = None
if self._client is not None:
# Close the AsyncDaytona client to release its underlying HTTP
# sessions and avoid leaking sockets across create/close cycles.
await self._client.close()
self._client = None
self._is_initialized = False

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def _daytona_patch(sandbox: mock.MagicMock):
"""Patch AsyncDaytona to return a mock client."""
mock_client = mock.MagicMock(name="AsyncDaytona")
mock_client.create = mock.AsyncMock(return_value=sandbox)
mock_client.close = mock.AsyncMock()

with mock.patch.object(daytona, "AsyncDaytona", autospec=True) as mock_class:
mock_class.return_value = mock_client
Expand Down Expand Up @@ -103,14 +104,18 @@ async def test_close_deletes_sandbox_and_is_idempotent(daytona_patch, sandbox):
env = DaytonaEnvironment()
await env.initialize()
assert env.is_initialized is True
client = daytona_patch.return_value
await env.close()
sandbox.delete.assert_awaited_once()
client.close.assert_awaited_once()
assert env._sandbox is None
assert env._client is None
assert env.is_initialized is False

# Second close is a no-op.
await env.close()
sandbox.delete.assert_awaited_once()
client.close.assert_awaited_once()


async def test_working_dir_requires_initialize():
Expand Down