mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 13:34:17 +02:00
fix: skip wait_closed() on Windows to avoid socket shutdown hang
This commit is contained in:
parent
0d96f88d59
commit
faa897b7d7
2 changed files with 5 additions and 15 deletions
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue