Skip to content

How to set timeout for session #475

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

Open
sei-li-miidas opened this issue Apr 10, 2025 · 2 comments
Open

How to set timeout for session #475

sei-li-miidas opened this issue Apr 10, 2025 · 2 comments

Comments

@sei-li-miidas
Copy link

sei-li-miidas commented Apr 10, 2025

async with ClientSession(
                read, write, timedelta(seconds=60 * 5)
            ) as session:
    await session.initialize()

I turned on debug log, and I can see in log, the timeout is 5.
[2025-04-10 21:45:10,055] [DEBUG] [httpcore.connection]: connect_tcp.started host='xxx' port=xxx local_address=None timeout=5.0 socket_options=None

And I debugged into AnyIO, the timeout outputted in log is connect timeout, but timeout for connect/read/write/pool are all 5.

Though
https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/shared/session.py#L247-L252
has the timeout logic, but I always get
[2025-04-10 22:12:21,674] [DEBUG] [httpcore.http11]: receive_response_headers.failed exception=ReadTimeout(TimeoutError())
this error, if it takes more than 5 seconds.

@sei-li-miidas
Copy link
Author

sei-li-miidas commented Apr 10, 2025

It seems because timeout isn't set at here, httpx uses its default timeout which is 5 seconds.
So when it takes more than 5 seconds, exception ReadTimeout('') happens here

@xinwo
Copy link

xinwo commented Apr 11, 2025

#479
fixes the problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants