Skip to content

Commit 6a703a4

Browse files
Fix ResourceWarning by properly closing file handles in DummyProcess
The DummyProcess class wasn't closing file handles in its __aexit__ method, causing ResourceWarning errors in CI tests on Windows. This commit adds proper cleanup to close both the async stream wrappers and underlying raw file handles when the process context manager exits. This prevents file descriptor leaks and eliminates the ResourceWarning errors seen in pytest output on Windows CI.
1 parent fc775e9 commit 6a703a4

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/mcp/client/stdio/win32.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ async def __aexit__(
7979
self.popen.terminate()
8080
await to_thread.run_sync(self.popen.wait)
8181

82+
# Close the file handles to prevent ResourceWarning
83+
if self.stdin:
84+
await self.stdin.aclose()
85+
if self.stdout:
86+
await self.stdout.aclose()
87+
if self.stdin_raw:
88+
self.stdin_raw.close()
89+
if self.stdout_raw:
90+
self.stdout_raw.close()
91+
if self.stderr:
92+
self.stderr.close()
93+
8294
async def wait(self):
8395
"""Async wait for process completion."""
8496
return await to_thread.run_sync(self.popen.wait)

0 commit comments

Comments
 (0)