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
5 changes: 5 additions & 0 deletions src/claude_agent_sdk/_internal/transport/subprocess_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,11 @@ async def close(self) -> None:
await self._stderr_stream.aclose()
self._stderr_stream = None

if self._stdout_stream:
with suppress(Exception):
await self._stdout_stream.aclose()
self._stdout_stream = None

# Terminate and wait for process
if self._process.returncode is None:
with suppress(ProcessLookupError):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,19 @@ async def _test():
assert transport._process is not None
assert transport.is_ready()

# Replace internal streams with mocks to verify close() calls aclose()
mock_stdout_stream = MagicMock()
mock_stdout_stream.aclose = AsyncMock()
transport._stdout_stream = mock_stdout_stream

mock_stderr_stream = MagicMock()
mock_stderr_stream.aclose = AsyncMock()
transport._stderr_stream = mock_stderr_stream

await transport.close()
mock_process.terminate.assert_called_once()
mock_stdout_stream.aclose.assert_called_once()
mock_stderr_stream.aclose.assert_called_once()

anyio.run(_test)

Expand Down