Skip to content

Multiple concurrent http requests to non-existing HTTP/2 endpoint takes a long time to time-out #114957

@SaxoAnders

Description

@SaxoAnders

Description

When doing multiple concurrent HTTP/2 requests to an endpoint that does not exists (e.g. because a gRPC service was just shut down), each request is timed out one at a time, which causes the last requests to time out very slowly.

Issue can be reproduced with the following snippet:

var httpClient = new HttpClient();

Console.WriteLine(DateTime.Now);
var tasks = Enumerable.Range(1, 10).Select(async x =>
{
    try
    {
        var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:8080/test")
        {
            Version = new Version(2, 0),
            VersionPolicy = HttpVersionPolicy.RequestVersionExact
        };

        await httpClient.SendAsync(request);
    }
    catch (Exception) { }
    Console.WriteLine(DateTime.Now);
});

Task.WaitAll(tasks.ToArray());
Console.WriteLine("Done");

Expected output is that all requests time out at approximately the same time, instead I see something like:

23-04-2025 14:27:27
23-04-2025 14:27:31
23-04-2025 14:27:35
23-04-2025 14:27:39
23-04-2025 14:27:44
23-04-2025 14:27:48
23-04-2025 14:27:52
23-04-2025 14:27:56
23-04-2025 14:28:00
23-04-2025 14:28:04
23-04-2025 14:28:08
Done

Removing either Version = new Version(2, 0) or VersionPolicy = HttpVersionPolicy.RequestVersionExact makes all requests time out after ~4 seconds.

Regression?

I am not aware of any .NET version that does not have this issue.

Analysis

My guess is that this is caused by HTTP/2 trying to multiplex multiple requests through the same connection, but I think if first requests times out because endpoint does not exist, then all request in queue should just be timed out immediately.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions