MCP session disposal throws ObjectDisposedException by accessing an expired HttpContext
维护者通常 2 天内回复
评估
调研方向
Start with McpServer.cs around line 129 and trace RunSessionHandler through its finally block. Review the existing EndedSession_RemovesLocationSubscription test and add regression coverage for disposal after the initialization request ends. Done means teardown releases subscriptions and applicable legacy admission state without throwing an ObjectDisposedException; pull request #250 is already open against this issue.
由索引模型根据 Issue 内容生成。
描述
Description
Observed with Cosmos DB Shell 1.1.280-preview on macOS through a VS Code MCP client. The account connection succeeded; session cleanup subsequently logged:
Error disposing session.
System.ObjectDisposedException: IFeatureCollection has been disposed.
Object name: 'Collection'.
at Microsoft.AspNetCore.Http.DefaultHttpRequest.get_Path()
at Azure.Data.Cosmos.Shell.Mcp.McpServer...
ConfigureHttpTransport... in McpServer.cs:line 137
at ModelContextProtocol.AspNetCore.StreamableHttpSession.DisposeAsync()
at ModelContextProtocol.AspNetCore.StatefulSessionManager.DisposeSessionAsync(...)
The unsafe access remains in McpServer.cs on main. The updated local main and origin/main both pointed to 6875685c6a2670ffcf85cdecff13420eea3a0a9b when checked.
Cause
RunSessionHandler awaits RunSessionAsync, then its finally block accesses httpContext.Request.Path and potentially httpContext.RequestServices. The originating HTTP request can already be disposed when the longer-lived MCP session ends.
This also affects non-legacy stateful sessions: evaluating the "/sse" condition itself dereferences the disposed context.
Expected Behavior
Session teardown completes without accessing expired request state, while releasing subscriptions and applicable legacy admission state.
Suggested Fix
Capture the legacy-transport decision and required singleton services before awaiting the session. Use only those captured values during cleanup.
Regression Coverage
Exercise session disposal after the initialization HTTP request has ended. Assert both successful cleanup and absence of disposal exceptions.
The existing EndedSession_RemovesLocationSubscription test checks subscription removal, but that cleanup occurs before the failing outer finally; it therefore does not establish error-free teardown.
Scope
The observed failure is in session cleanup. It does not establish that preceding tool calls failed or that unrelated Azure deployment operations were affected.
- 主要语言
- C#
- 星标
- 4
- 派生
- 7
- 平均合并
- 2 天 40 分钟
- 30 天内合并 PR
- 30
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
Azure/CosmosDBShell 的其他 Issue
-
Support undefined partition keys (PartitionKey.None) across item commands可能已有人在做 @mkrueger 于 1 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 15/100
Azure/CosmosDBShell#251 ·
维护者通常 2 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 25/100
Azure/CosmosDBShell#240 ·
维护者通常 2 天内回复
-
automation P1
难度 5/5 一周以上 新手友好度 45/100
Azure/CosmosDBShell#178 · 1 条评论 ·
维护者通常 2 天内回复
-
Lightweight headless CI distribution (no MCP, LSP, interactive UI)可能重新可做 关联的 PR 已关闭且未合并。 未关闭automation P1
难度 5/5 一周以上 新手友好度 35/100
Azure/CosmosDBShell#175 · 1 条评论 ·
维护者通常 2 天内回复
-
agentic enhancement P0
难度 4/5 3-5 天 新手友好度 55/100
Azure/CosmosDBShell#153 · 1 条评论 ·
维护者通常 2 天内回复
查看 Azure/CosmosDBShell 的全部 Issue
相似的 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 62/100
Sector-Vestige/Sector-Vestige#476 ·
维护者通常 1 天内回复
-
S: Untriaged
难度 2/5 1-3 小时 新手友好度 62/100
Trauma-Station/Trauma-Station#5058 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 2 天内回复
-
难度 1/5 1 小时以内 新手友好度 75/100
HoffmanEngineering/3d-print-log-api#243 ·
维护者通常 1 天内回复
-
:books: documentation untriaged
难度 2/5 1-3 小时 新手友好度 66/100
维护者通常 1 天内回复