Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

MCP session disposal throws ObjectDisposedException by accessing an expired HttpContext

Đang mở
#249 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 2 ngày

@mkrueger đang làm issue này rồi.

Từ ngày 13/10/2026.

  • #250 của @mkrueger — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
csharp
Lĩnh vực
backend, cli

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
C#
Star
4
Fork
7
Merge trung bình
2 ngày 13 phút
Pull request đã merge (30 ngày)
30

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của Azure/CosmosDBShell

Tất cả issue của Azure/CosmosDBShell

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.