fix: skip wait_closed() on Windows to avoid socket shutdown hang

This commit is contained in:
Chris Guidry 2025-12-05 12:30:27 -05:00
commit faa897b7d7
2 changed files with 5 additions and 15 deletions

View file

@ -34,6 +34,7 @@ async def _wait_for_port(
interval: Time between connection attempts
"""
import asyncio
import sys
start = 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()
return
except (OSError, asyncio.TimeoutError):
if asyncio.get_running_loop().time() - start > timeout:

View file

@ -2,26 +2,12 @@ import socket
from collections.abc import Callable
from pathlib import Path
from typing import Any
from unittest.mock import patch
import pytest
from 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: