π The fast, Pythonic way to build MCP servers and clients.
fix: skip wait_closed() on Windows to avoid socket shutdown hang
Chris Guidryfaa897b7d782
diff --git a/src/fastmcp/utilities/tests.py b/src/fastmcp/utilities/tests.pyindex 1a4a12b05..6b7b28194 100644--- a/src/fastmcp/utilities/tests.py+++ b/src/fastmcp/utilities/tests.py@@ -34,6 +34,7 @@ async def _wait_for_port(interval: Time between connection attempts"""import asyncio+ import sysstart = asyncio.get_running_loop().time()while True:@@ -42,7 +43,10 @@ async def _wait_for_port(asyncio.open_connection(host, port), timeout=interval)writer.close()- await writer.wait_closed()+ # On Windows, wait_closed() can hang due to ProactorEventLoop socket+ # shutdown issues. Skip it - the socket will be cleaned up eventually.+ if sys.platform != "win32":+ await writer.wait_closed()returnexcept (OSError, asyncio.TimeoutError):if asyncio.get_running_loop().time() - start > timeout:diff --git a/tests/conftest.py b/tests/conftest.pyindex 7c524b5ee..22487f97e 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -2,26 +2,12 @@ import socketfrom collections.abc import Callablefrom pathlib import Pathfrom typing import Any-from unittest.mock import patchimport pytestfrom fastmcp.utilities.tests import temporary_settings-# Fakeredis connection pool disconnect can hang on Windows due to ProactorEventLoop-# socket shutdown issues. Since fakeredis uses in-memory connections that don't need-# proper network cleanup, we skip the disconnect entirely in tests.-async def _fast_disconnect(self):- pass---_disconnect_patch = patch(- "redis.asyncio.connection.ConnectionPool.disconnect", _fast_disconnect-)-_disconnect_patch.start()--def pytest_collection_modifyitems(items):"""Automatically mark tests in integration_tests folder with 'integration' marker."""for item in items: