Skip to content

How to set timeout for session #475

Description

@sei-li-miidas
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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions