Skip to content

McpClient.DisposeAsync() Hangs indefinitely when HttpClientTransportOptions.OwnsSession is set to false #1250

@henrydn

Description

@henrydn

Version
Issue occurs on 0.8.0-preview.1 and 0.7.0-preview.1

Describe the bug
When HttpClientTransportOptions.OwnsSession is set to false, McpClient.DisposeAsync() hangs indefinitely

To Reproduce
Steps to reproduce the behavior:

var httpClient = httpClientFactory.CreateClient("McpClient");
      
var httpTransportOptions = new HttpClientTransportOptions
{
    Endpoint = new Uri(_config.Uri),
    OwnsSession = false // set to false so that we don't delete the session when the MCP client is disposed
};

var client = await McpClient.CreateAsync(new HttpClientTransport(httpTransportOptions, httpClient), 
    new McpClientOptions(), cancellationToken: ct);

var response = await client.CallToolAsync(Name, arguments, cancellationToken: ct);

// Dispose hangs forever in StreamableHttpClientSessionTransport.DisposeAsync();
await client.DisposeAsync();

Expected behavior
I'm expecting McpClient.DisposeAsync() to return eventually

Additional context
When HttpClientTransportOptions.OwnsSession is true, DisposeAsync() doesn't hang. But then it deletes the session on the server which is not what we want

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions