René's URL Explorer Experiment


Title: HttpServletStreamableServerTransportProvider orphans sessions on first transient SSE write failure (no grace period) · Issue #920 · modelcontextprotocol/java-sdk · GitHub

Open Graph Title: HttpServletStreamableServerTransportProvider orphans sessions on first transient SSE write failure (no grace period) · Issue #920 · modelcontextprotocol/java-sdk

X Title: HttpServletStreamableServerTransportProvider orphans sessions on first transient SSE write failure (no grace period) · Issue #920 · modelcontextprotocol/java-sdk

Description: Summary In HttpServletStreamableServerTransportProvider, a single failed SSE write immediately removes the session from the in-memory map, so the client's next POST gets Session not found even though the failure was transient (LB respons...

Open Graph Description: Summary In HttpServletStreamableServerTransportProvider, a single failed SSE write immediately removes the session from the in-memory map, so the client's next POST gets Session not found even thou...

X Description: Summary In HttpServletStreamableServerTransportProvider, a single failed SSE write immediately removes the session from the in-memory map, so the client's next POST gets Session not found even ...

Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/920

X: @github

direct link

Domain: github.com


Hey, it has json ld scripts:
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"HttpServletStreamableServerTransportProvider orphans sessions on first transient SSE write failure (no grace period)","articleBody":"## Summary\n\nIn `HttpServletStreamableServerTransportProvider`, a single failed SSE write\nimmediately removes the session from the in-memory map, so the client's next\nPOST gets `Session not found` even though the failure was transient (LB\nresponse-timeout, NEG rebalance, pod eviction, laptop sleep, mobile network\nblip). The client is forced into a full `initialize` round-trip and loses\nany server-side session state.\n\nAdding a short, configurable **grace period** before `sessions.remove(...)`\n— during which a reconnect with the same session id reattaches — would solve\nthis without touching where sessions are stored or how resumability works.\n\nA secondary, unrelated observation about a duplicate `asyncContext.complete()`\ncall is noted at the bottom.\n\n## Relationship to existing work\n\nI want to flag upfront how this differs from related open issues/PRs, so it's\neasy to triage.\n\n- **#914** (`McpSessionStore` SPI) — changes *where* sessions live\n  (pluggable store: Redis, JDBC, Hazelcast). Great for restart/cluster\n  scenarios. Orthogonal to this issue: even with a Redis-backed store, one\n  failed write to one client still triggers `sessions.remove(sessionId)`\n  and orphans **that** client's session.\n- **#830** (`Last-Event-ID` resumability) — adds an event store and wires\n  replay through `GET /mcp`. Complementary to this issue but requires the\n  session to still exist when the client reconnects. With today's eager\n  removal, replay is unreachable for the case described here.\n- **#107** (server-restart `Session not found`) — same symptom, different\n  trigger (process restart vs in-process transient write failure). #914\n  addresses #107; neither addresses the scenario below.\n- **#274 / #738 / #376 / #201** — persistence / clustering angles, all in\n  the same family as #914.\n\nThe ask here is narrower than any of those: **don't drop the session on the\nfirst transient write failure**.\n\n## Version\n\n- `io.modelcontextprotocol.sdk:mcp-core` 1.1.0\n- JDK 25, Tomcat (Spring Boot 4), behind a GKE HTTP(S) LB\n\n## Reproduction\n\n1. Run any gateway built on `HttpServletStreamableServerTransportProvider`\n   behind an L7 LB that caps per-response duration below the session lifetime\n   (GKE `BackendConfig.timeoutSec` ≤ 60 s is a clean repro).\n2. Connect an MCP client (seen with `claude-code`, but any streamable-HTTP\n   client triggers it).\n3. Wait for the LB to close the SSE stream (~60 s in our case).\n4. Observe — server log:\n\n   ```\n   KeepAliveScheduler: Failed to send keep-alive ping to session ...:\n     Did not observe any item or terminal signal within 10000ms in 'source(MonoCreate)'\n   ServletStreamableServerTransportProvider:\n     Failed to send message to session ...: Client disconnected\n   ```\n\n   Client gets `Session not found` on its next POST.\n\n## Root cause\n\n`HttpServletStreamableMcpSessionTransport.sendMessage` (v1.1.0, lines 738–767)\nhard-codes session removal in the catch block:\n\n```java\n@Override\npublic Mono\u003cVoid\u003e sendMessage(McpSchema.JSONRPCMessage message, String messageId) {\n    return Mono.fromRunnable(() -\u003e {\n        ...\n        try {\n            ...\n            String jsonText = jsonMapper.writeValueAsString(message);\n            HttpServletStreamableServerTransportProvider.this.sendEvent(writer, MESSAGE_EVENT_TYPE, jsonText,\n                    messageId != null ? messageId : this.sessionId);\n            ...\n        }\n        catch (Exception e) {\n            logger.error(\"Failed to send message to session {}: {}\", this.sessionId, e.getMessage());\n            HttpServletStreamableServerTransportProvider.this.sessions.remove(this.sessionId); // \u003c— here\n            this.asyncContext.complete();\n        }\n        ...\n    });\n}\n```\n\nNo grace, no policy hook, no listener. `sessions` is a `private final Map`\nand `HttpServletStreamableMcpSessionTransport` is a private inner class, so\ndownstream apps cannot override the behaviour without reflection.\n\n## Proposal\n\nTwo shapes, from least to most invasive:\n\n### 1. Configurable session-retention grace period (minimal, recommended)\n\nAdd `Builder.sessionReconnectGracePeriod(Duration)`, defaulting to\n`Duration.ZERO` (current behaviour, fully backward compatible). On write\nfailure:\n\n- mark the session as detached (new flag on the session transport);\n- schedule a removal task at `now + grace` on a shared scheduled executor;\n- on an incoming `GET /mcp` whose session id matches, clear the detach flag,\n  cancel the scheduled removal, and let the existing `Last-Event-ID` replay\n  path (SDK lines 327–349) or #830's event-store path run.\n\nWith `grace = Duration.ZERO`, behaviour is identical to today. With\n`grace \u003e 0`, transient blips no longer orphan clients. Composes naturally\nwith #914 (pluggable store) and #830 (replay).\n\n### 2. Session lifecycle listener (larger, general-purpose)\n\nAdd a `SessionLifecycleListener` interface on the builder with\n`onSessionDetached`, `onSessionReconnected`, `onSessionClosed`. Ship the\ncurrent eager-remove behaviour as the default listener; apps can register\na custom listener with whatever retention policy suits their deployment.\n\nI'd prefer option 1 — it solves the concrete problem without opening a\nbroader API-surface question.\n\n## Secondary observation — duplicate `asyncContext.complete()`\n\nSame file: the catch block in `sendMessage` (line 761) and `close()`\n(line ~811) both call `asyncContext.complete()`. When a write failure is\nfollowed by a close, the second call races with the servlet container's\nstate machine and produces:\n\n```\nFailed to complete async context ... Async state [COMPLETING]\n```\n\nCosmetic, but pollutes logs. A flag (e.g. `asyncContextCompleted` set on\nfirst call, checked before the second) would silence it.\n\n## Willing to contribute\n\nHappy to open a PR for either of the above if the maintainers would welcome\nthe contribution — just want to confirm the approach and that option 1 is\nthe direction you'd prefer before writing code.","author":{"url":"https://github.com/andersenleo","@type":"Person","name":"andersenleo"},"datePublished":"2026-04-15T07:51:32.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/920/java-sdk/issues/920"}

route-pattern/_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format)
route-controllervoltron_issues_fragments
route-actionissue_layout
fetch-noncev2:0b22a97b-9825-f6e7-e446-8411e45fad9b
current-catalog-service-hash81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114
request-id8E2C:3AA36:1E8CA2C:291FAC3:6A598BC9
html-safe-nonce55d1d71e3ba388131fc6f10210645d3f4c664d2d829726fcffcdead696d3e2e7
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTJDOjNBQTM2OjFFOENBMkM6MjkxRkFDMzo2QTU5OEJDOSIsInZpc2l0b3JfaWQiOiIzNjU3ODIwNDkxNTM5Mzg1Mjg5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0=
visitor-hmac3505eee2a9ba83b9d1ce4854090628acef90385b564c431340ad0698ade54e37
hovercard-subject-tagissue:4267191328
github-keyboard-shortcutsrepository,issues,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///voltron/issues_fragments/issue_layout
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/java-sdk/920/issue_layout
twitter:imagehttps://opengraph.githubassets.com/6e791b1147ae5c237af9b8f8d70aa157595565ab08c05dbbf28cb36d1d21c433/modelcontextprotocol/java-sdk/issues/920
twitter:cardsummary_large_image
og:imagehttps://opengraph.githubassets.com/6e791b1147ae5c237af9b8f8d70aa157595565ab08c05dbbf28cb36d1d21c433/modelcontextprotocol/java-sdk/issues/920
og:image:altSummary In HttpServletStreamableServerTransportProvider, a single failed SSE write immediately removes the session from the in-memory map, so the client's next POST gets Session not found even thou...
og:image:width1200
og:image:height600
og:site_nameGitHub
og:typeobject
og:author:usernameandersenleo
hostnamegithub.com
expected-hostnamegithub.com
Nonea540949572872b935b393b36db38922db390ae71c859537d741b8f3eb7e545b5
turbo-cache-controlno-preview
go-importgithub.com/modelcontextprotocol/java-sdk git https://github.com/modelcontextprotocol/java-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id919609219
octolytics-dimension-repository_nwomodelcontextprotocol/java-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id919609219
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/java-sdk
turbo-body-classeslogged-out env-production page-responsive
disable-turbofalse
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release624bb50a7497aa346bef8cc3743af408a9ea10ca
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/java-sdk/issues/920#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fjava-sdk%2Fissues%2F920
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fjava-sdk%2Fissues%2F920
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fvoltron%2Fissues_fragments%2Fissue_layout&source=header-repo&source_repo=modelcontextprotocol%2Fjava-sdk
Reloadhttps://github.com/modelcontextprotocol/java-sdk/issues/920
Reloadhttps://github.com/modelcontextprotocol/java-sdk/issues/920
Reloadhttps://github.com/modelcontextprotocol/java-sdk/issues/920
Please reload this pagehttps://github.com/modelcontextprotocol/java-sdk/issues/920
modelcontextprotocol https://github.com/modelcontextprotocol
java-sdkhttps://github.com/modelcontextprotocol/java-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fjava-sdk
Fork 979 https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fjava-sdk
Star 3.6k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fjava-sdk
Code https://github.com/modelcontextprotocol/java-sdk
Issues 131 https://github.com/modelcontextprotocol/java-sdk/issues
Pull requests 146 https://github.com/modelcontextprotocol/java-sdk/pulls
Discussions https://github.com/modelcontextprotocol/java-sdk/discussions
Actions https://github.com/modelcontextprotocol/java-sdk/actions
Projects https://github.com/modelcontextprotocol/java-sdk/projects
Models https://github.com/modelcontextprotocol/java-sdk/models
Security and quality 2 https://github.com/modelcontextprotocol/java-sdk/security
Insights https://github.com/modelcontextprotocol/java-sdk/pulse
Code https://github.com/modelcontextprotocol/java-sdk
Issues https://github.com/modelcontextprotocol/java-sdk/issues
Pull requests https://github.com/modelcontextprotocol/java-sdk/pulls
Discussions https://github.com/modelcontextprotocol/java-sdk/discussions
Actions https://github.com/modelcontextprotocol/java-sdk/actions
Projects https://github.com/modelcontextprotocol/java-sdk/projects
Models https://github.com/modelcontextprotocol/java-sdk/models
Security and quality https://github.com/modelcontextprotocol/java-sdk/security
Insights https://github.com/modelcontextprotocol/java-sdk/pulse
HttpServletStreamableServerTransportProvider orphans sessions on first transient SSE write failure (no grace period)https://github.com/modelcontextprotocol/java-sdk/issues/920#top
waiting for triagehttps://github.com/modelcontextprotocol/java-sdk/issues?q=state%3Aopen%20label%3A%22waiting%20for%20triage%22
https://github.com/andersenleo
andersenleohttps://github.com/andersenleo
on Apr 15, 2026https://github.com/modelcontextprotocol/java-sdk/issues/920#issue-4267191328
feat: add McpSessionStore SPI for pluggable session storage #914https://github.com/modelcontextprotocol/java-sdk/pull/914
Support last event Id for resumability of sse #830https://github.com/modelcontextprotocol/java-sdk/pull/830
Session not found handling #107https://github.com/modelcontextprotocol/java-sdk/issues/107
feat: add McpSessionStore SPI for pluggable session storage #914https://github.com/modelcontextprotocol/java-sdk/pull/914
Session not found handling #107https://github.com/modelcontextprotocol/java-sdk/issues/107
McpServerSession lifecycle doesn't support distributed services #274https://github.com/modelcontextprotocol/java-sdk/issues/274
I would like to maintain MCP server state persisted (sessionId) #738https://github.com/modelcontextprotocol/java-sdk/issues/738
Proposal: Add client state persistence API to allow MCP clients to survive restarts #376https://github.com/modelcontextprotocol/java-sdk/issues/376
MCP Server can not support cluster #201https://github.com/modelcontextprotocol/java-sdk/issues/201
feat: add McpSessionStore SPI for pluggable session storage #914https://github.com/modelcontextprotocol/java-sdk/pull/914
Support last event Id for resumability of sse #830https://github.com/modelcontextprotocol/java-sdk/pull/830
#914https://github.com/modelcontextprotocol/java-sdk/pull/914
#830https://github.com/modelcontextprotocol/java-sdk/pull/830
waiting for triagehttps://github.com/modelcontextprotocol/java-sdk/issues?q=state%3Aopen%20label%3A%22waiting%20for%20triage%22
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.