fix: clean up idle streamable HTTP sessions - #1087
Conversation
|
Hi maintainers — a gentle follow-up on this PR. The branch has been synchronized with the current |
|
I saw that #471 was closed in favor of #1022. #1022 and #1028 focus on evicting sessions after repeated keep-alive ping failures, and #1028 explicitly leaves a general session TTL out of scope. This PR covers a separate fallback: an optional idle TTL, disabled by default, that can also clean up abandoned sessions when keep-alive is not configured, while protecting active requests and open SSE streams. Would you like the idle TTL capability to remain as a separate follow-up after #1028, or should I close this PR in favor of the keep-alive-based approach? I will avoid rebasing or making further changes until the intended scope is clear. |
Add an optional, backward-compatible idle timeout to
HttpServletStreamableServerTransportProvider.The timeout is disabled by default. When configured, the provider records session
activity and expires only sessions that have remained genuinely idle beyond the
configured timeout. Active requests and open SSE streams keep their sessions alive.
Motivation and Context
Streamable HTTP sessions currently remain in the provider session map until the
client sends an explicit
DELETErequest or the provider shuts down. Clients candisconnect, restart, or fail without sending
DELETE, causing abandoned sessionsto accumulate indefinitely.
This implements the TTL and recency-marker approach discussed in #471 while
preserving the existing default behavior.
Fixes #471
How Has This Been Tested?
./mvnw -pl mcp-core -Dtest=HttpServletStreamableServerSessionTimeoutTests,HttpServletRequestUtilsTests test./mvnw -pl mcp-core clean test./mvnw -pl mcp-test -am -Dtest=HttpServletStreamableIntegrationTests -Dsurefire.failIfNoSpecifiedTests=false testgit diff --check origin/main...HEADThe focused timeout tests cover:
The branch was synchronized with the latest
main, preserving the upstreamrequestMaxSizebehavior and its HTTP 413 handling alongside session cleanup.No successful full-reactor test result is claimed.
Breaking Changes
None. Idle cleanup remains disabled unless
sessionTimeoutis explicitlyconfigured, and existing builder usage retains its previous behavior.
Types of changes
Checklist
Additional context
maxSessionslimit are outside this PR.disclosure.txtis included as required by the repository contribution policy.