Skip to content

Streamable HTTP: default session_idle_timeout=None plus mcp's max_sessions=10000 makes long-running servers fail with 503 "Too many open sessions" #5210

Closed

Description

@mguttmann

What happened?

A long-running FastMCP 4.x Streamable HTTP server eventually answers every request with HTTP 503 {"error":{"code":-32603,"message":"Too many open sessions"}} and never recovers until restarted.

Two defaults collide:

  • mcp 2.2.0 caps stateful Streamable HTTP sessions: StreamableHTTPSessionManager(session_idle_timeout=30*60, max_sessions=10_000) (mcp/server/streamable_http_manager.py, DEFAULT_SESSION_IDLE_TIMEOUT, DEFAULT_MAX_SESSIONS). Its own default reaps idle sessions after 30 minutes, so the cap is normally never reached.
  • FastMCP passes session_idle_timeout=None unless the user sets it (settings.http_session_idle_timeout defaults to None, documented as "sessions never expire from inactivity"; server/http.py hands it to FastMCPStreamableHTTPSessionManager). max_sessions is not passed, so the mcp cap of 10,000 stays active.

Result: every session that a client does not end with an explicit DELETE stays open forever, the pool fills up, and once it hits 10,000 the server is down for everyone. Most clients do not send DELETE on teardown (we measured 437 DELETE against 10,436 sessions created), so this is the normal case, not an edge case.

Measured on our gateway (FastMCP 4.0.5, mcp 2.2.0, httpx2 2.13.0, Python 3.12):

Created new transport   10436   (about 370 per hour, 30 hours after a restart)
Terminating session         0
Refusing to open a new session: 10000 sessions are already open   -> HTTP 503 for 12.5 hours
process RSS 1.4 GB at the cap, 0.57 GB after restart

/healthz-style liveness checks that do not look at the session pool stay green the whole time, so nothing restarts the process.

Reproduction

Defaults of a bare server after lifespan start:

import asyncio
from fastmcp import FastMCP

srv = FastMCP("probe")
app = srv.http_app(path="/mcp")

async def main():
    async with app.router.lifespan_context(app):
        sm = None
        for r in app.routes:
            sm = getattr(getattr(r, "app", None), "session_manager", None) or sm
        print("session_idle_timeout =", sm.session_idle_timeout, "max_sessions =", sm.max_sessions)

asyncio.run(main())

Output on FastMCP 4.0.5 / mcp 2.2.0:

session_idle_timeout = None max_sessions = 10000

To hit the cap quickly: run the server, send 10,001 initialize requests without DELETE (any client that reconnects instead of terminating does this over time). The 10,001st initialize gets the 503 above; so does every request after it.

Expected behaviour

Either of these would avoid the trap:

  1. Do not override the mcp default: leave session_idle_timeout at mcp's 30 minutes unless the user explicitly sets None. A bounded pool with a disabled reaper is a guaranteed outage for any server whose clients do not DELETE.
  2. If None stays the default, also expose max_sessions (mirroring mcp) and document the pair together, so operators see that "never expire" plus "cap at 10,000" means "restart required eventually".

Independently, it would help to surface the pool in a way operators can monitor (for example a counter on the session manager that http_app users can read), since the failure is invisible to liveness checks.

Workaround

Set the idle timeout explicitly, for example FASTMCP_HTTP_SESSION_IDLE_TIMEOUT=1800 or settings.http_session_idle_timeout = 1800 before run(); http_app() falls back to that setting. After doing so we see Session ... idle timeout in the log exactly 30 minutes after the first orphaned session and the pool stays at a few dozen entries.

Version Information

FastMCP 4.0.5 (fastmcp-slim 4.0.5), mcp 2.2.0, httpx2 2.13.0, Python 3.12.11, Linux (Ubuntu). Also reproduced with FastMCP 4.0.3.

Activity

  1. added
    bug
    http
    on Sep 22, 2026
  2. vineoy commented on Sep 22, 2026

    @vineoy

    Can confirm on 4.0.5 / mcp 2.2.0 - a fresh http_app() comes up with session_idle_timeout=None and max_sessions still at 10000. SDK defaults are 1800 / 10000, and the settings field says None means sessions never expire, so a default install ends up with a capped pool and nothing reaping it. Matches the 503 described here. Quick question for maintainers: should the default just follow the SDK 1800s, or keep None and expose max_sessions alongside it?

  3. added a commit that references this issue on Oct 5, 2026
    a35b88b
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

    bughigh-priorityhttp

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions