streamable-http server: stateful session workers ignore config.cancellation_token and stay alive until keep_alive after shutdown
维护者通常 3 天内回复
评估
这个 Issue 还没有评估数据。
描述
We run one StreamableHttpService per agent run: rmcp 3.7.0 with server and transport-streamable-http-server, LocalSessionManager::default(), and the default config plus with_cancellation_token(...). It sits behind axum::serve(...).with_graceful_shutdown(...). The client is a child process. When the run ends we kill it, cancel the token and wait for the server task. The client never sends DELETE.
The stateful session created by its initialize keeps running after that. In one trace the last tools/call response went out at 00:16:43.820 and our handler was dropped at 00:21:43.823. That is SessionConfig::DEFAULT_KEEP_ALIVE (300 s) after the last event the session worker handled. The worker task owns the handler, so whatever the handler holds lives that long too. For us that kept a per-run resource alive and held up teardown for five minutes.
Reading the code (the same paths are still on main):
StreamableHttpService::spawn_session_workerintower.rsis a plaintokio::spawn. Itsserve_servercall creates its ownCancellationToken.LocalSessionManager::create_sessionusesWorkerTransport::spawn(worker), which also starts from a fresh token. As far as I can tell,config.cancellation_tokenonly reaches the SSE response streams and the stateless path.- The worker task keeps an
Arcof the session manager, and the manager keeps theLocalSessionHandleand itsevent_tx. So dropping the service or router doesn't close the worker'sevent_rxeither. Only DELETE,close_sessionor the idle timeout end the session.
The doc comment on StreamableHttpServerConfig::cancellation_token says cancelling it terminates all active sessions, so either the docs or the behaviour is off.
Is the token meant to end stateful sessions as well? If so, passing a child of config.cancellation_token into the worker looks like it would fix this, either through WorkerTransport::spawn_with_ct in create_session or by racing it in spawn_session_worker. A way to close every session from the service or the manager on shutdown would work for us too.
For now we keep the Arc<LocalSessionManager>, call close_session for every entry in sessions once the server task has finished, and keep run-scoped state out of the handler.
Possibly related: #1325 (in-flight calls are not cancelled on disconnect in the session-manager path) and #857.
- 主要语言
- Rust
- 星标
- 4.1k
- 派生
- 694
- 平均合并
- 4 天 16 小时
- 30 天内合并 PR
- 43
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
modelcontextprotocol/rust-sdk 的其他 Issue
-
Return MergedList<T> from list_all_* and drop the _with_cache_hint variants可能已有人在做 @DaleSeo 于 2 天前认领。 未关闭enhancement P3 ready for work T-service v4
modelcontextprotocol/rust-sdk#1430 · 已指派 1 人 ·
维护者通常 3 天内回复
-
Server logs a fabricated 'initialize' (with synthesized rmcp/3.8.0 peer identity) for no-initialize SEP-2567 requests, ignoring clientInfo from _meta可能已有人在做 @jamadeo 于 3 天前认领。 未关闭bug P2 ready for work T-service T-transport
modelcontextprotocol/rust-sdk#1425 · 2 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
OAuth discovery drops explicit default ports from advertised issuer identifiers可能已有人在做 @gocamille 于 5 天前认领。 未关闭bug P1 ready for work T-security T-transport
modelcontextprotocol/rust-sdk#1420 · 3 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
`register_client` drops `client_secret_expires_at` from the registration response可能已有人在做 @gocamille 于 6 天前认领。 未关闭bug P2 ready for work T-security
modelcontextprotocol/rust-sdk#1416 · 1 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
-
Typed client calls drop the parse error when a reply misses a required field可能已有人在做 @gocamille 于 6 天前认领。 未关闭enhancement P2 ready for work T-core T-service
modelcontextprotocol/rust-sdk#1415 · 1 条评论 · 已指派 1 人 ·
维护者通常 3 天内回复
查看 modelcontextprotocol/rust-sdk 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
NSPG13/agent-bounties#1749 ·
维护者通常 1 天内回复
-
area: web bug
难度 2/5 1-3 小时 新手友好度 76/100
kinqsradio/orbyn-engineering#227 ·
维护者通常 1 天内回复
-
agentic-workflows automation repo-assist
难度 1/5 1 小时以内 新手友好度 85/100
shanselman/winget-tui#483 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
lightonai/next-plaid#205 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
apache/datafusion-iceberg#100 ·
维护者通常 1 天内回复