Skip to content

Evict streamable HTTP sessions after failed keep-alive pings#1028

Open
lxq19991111 wants to merge 1 commit into
modelcontextprotocol:mainfrom
lxq19991111:fix/keepalive-dead-session-eviction-clean
Open

Evict streamable HTTP sessions after failed keep-alive pings#1028
lxq19991111 wants to merge 1 commit into
modelcontextprotocol:mainfrom
lxq19991111:fix/keepalive-dead-session-eviction-clean

Conversation

@lxq19991111

Copy link
Copy Markdown

Summary

Fixes #1022.

This PR fixes dead Streamable HTTP sessions accumulating when keep-alive pings fail after a client disconnects.

  • Add success and failure callbacks to KeepAliveScheduler, with default no-op handlers so existing scheduler users
    keep the same behavior.
  • Track consecutive keep-alive ping failures in HttpServletStreamableServerTransportProvider.
  • Evict and close a Streamable HTTP session after 3 consecutive keep-alive ping failures.
  • Clear failure counts after successful pings, session deletion, shutdown, and transport send failure.
  • Guard failure-count reset and eviction with session identity checks so stale keep-alive results cannot affect a
    replaced session.
  • Add tests for scheduler callbacks and Streamable HTTP keep-alive eviction behavior.

Notes

The issue suggested doing the counter/removal directly in KeepAliveScheduler. This PR keeps KeepAliveScheduler
transport-agnostic and exposes success/failure hooks instead. The Streamable HTTP servlet provider owns the session
map, so it also owns eviction.

This PR intentionally does not modify the deprecated HttpServletSseServerTransportProvider.

This PR also does not include the separate async lifecycle / socket cleanup work.

Testing

  • mvn -pl mcp-core -Dtest=KeepAliveSchedulerTests,HttpServletStreamableServerTransportProviderTests test
  • mvn -pl mcp-core test

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

Successfully merging this pull request may close these issues.

[BUG] KeepAliveScheduler does not evict sessions after ping failure, causing unbounded CPU growth

1 participant