-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix HTTP transport timeout defaulting to 5 seconds #2849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4f671d9
592d0da
f3d31eb
9b33a05
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| """Test that verifies the timeout fix for issue #2842 and #2845.""" | ||
|
|
||
| import asyncio | ||
|
|
||
| import pytest | ||
|
|
||
| from fastmcp import FastMCP | ||
| from fastmcp.client import Client | ||
| from fastmcp.client.transports import StreamableHttpTransport | ||
| from fastmcp.utilities.tests import run_server_async | ||
|
|
||
|
|
||
| def create_test_server() -> FastMCP: | ||
| """Create a FastMCP server with a slow tool.""" | ||
| server = FastMCP("TestServer") | ||
|
|
||
| @server.tool | ||
| async def slow_tool(duration: int = 6) -> str: | ||
| """A tool that takes some time to complete.""" | ||
| await asyncio.sleep(duration) | ||
| return f"Completed in {duration} seconds" | ||
|
|
||
| return server | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| async def streamable_http_server(): | ||
| """Start a test server and return its URL.""" | ||
| server = create_test_server() | ||
| async with run_server_async(server) as url: | ||
| yield url | ||
|
|
||
|
|
||
| @pytest.mark.integration | ||
| @pytest.mark.timeout(15) | ||
| async def test_slow_tool_with_http_transport(streamable_http_server: str): | ||
| """Test that tools taking >5 seconds work correctly with HTTP transport. | ||
|
|
||
| This test verifies the fix for: | ||
| - Issue #2842: Client can't get result after upgrading to 2.14.2 | ||
| - Issue #2845: Server doesn't return results when tool takes >5 seconds | ||
|
|
||
| The root cause was that the httpx client was created without explicit | ||
| timeout configuration, defaulting to httpx's 5-second timeout. | ||
| """ | ||
| async with Client( | ||
| transport=StreamableHttpTransport(streamable_http_server) | ||
| ) as client: | ||
| # This should NOT timeout since we fixed the default timeout | ||
| result = await client.call_tool("slow_tool", {"duration": 6}) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This test exercises a 6‑second tool call, but the repo’s pytest configuration sets a default timeout of 5 seconds ( Useful? React with 👍 / 👎. |
||
| assert result.data == "Completed in 6 seconds" | ||
Uh oh!
There was an error while loading. Please reload this page.