Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

MCP session disposal throws ObjectDisposedException by accessing an expired HttpContext

Fechada
#249 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 2 dias

@mkrueger já está trabalhando nisso.

Desde 13/10/2026.

  • #250 de @mkrueger — aberto

Avaliação

Dificuldade
3/5
Tempo estimado
1-2 dias
Facilidade para iniciantes
35/100
Tipo de issue
Bug
Clareza
Claramente especificada
Status de atividade
Estagnada
Stack de tecnologia
csharp
Domínio
backend, cli

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
C#
Estrelas
4
Forks
7
Merge médio
2d 40min
PRs com merge (30d)
30

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de Azure/CosmosDBShell

Todas as issues de Azure/CosmosDBShell

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.