Skip to content

Commit c3dc56a

Browse files
fix(client): remove manual task cancellation to fix process cleanup
ROOT CAUSE: Manual tg.cancel_scope.cancel() was interfering with process cleanup in the async with block, causing CancelledError and ProcessLookupError during process termination. CHANGES: - Removed tg.cancel_scope.cancel() call from finally block - The async with block already handles task cancellation when exiting IMPACT: - Fixes test_stdio_client_sigint_only_process failure - Process cleanup now completes without interference - Background tasks still properly cancelled by task group exit FILES MODIFIED: - src/mcp/client/stdio.py
1 parent 701e4d7 commit c3dc56a

File tree

1 file changed

+0
-4
lines changed

1 file changed

+0
-4
lines changed

src/mcp/client/stdio.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,6 @@ async def stdin_writer():
206206
# Process already exited, which is fine
207207
pass
208208

209-
# Cancel background tasks before closing streams to prevent race condition
210-
# where tasks try to use closed streams (BrokenResourceError)
211-
tg.cancel_scope.cancel()
212-
213209
await read_stream.aclose()
214210
await write_stream.aclose()
215211
await read_stream_writer.aclose()

0 commit comments

Comments
 (0)