Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

MCP session disposal throws ObjectDisposedException by accessing an expired HttpContext

Aperta
#249 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 2 giorni

@mkrueger ci sta già lavorando.

Dal 13/10/2026.

  • #250 di @mkrueger — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
csharp
Ambito
backend, cli

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C#
Stelle
4
Fork
7
Merge medio
2g 13m
PR unite (30g)
30

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Azure/CosmosDBShell

Tutte le issue di Azure/CosmosDBShell

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.