Skip to content

[API Proposal]: Initial HTTP/2 stream limit on SocketsHttpHandler #132457

Closed

Description

@MihaZupan

Background and motivation

HTTP/2 has an inherent race condition during connection establishment.
The stream limit is advertised by the server in a SETTINGS frame, but the client is free to send requests immediately after a connection is established, even before it observes the settings.
As a result the client may send more requests than the server limit, which causes many of those requests to fail. Some may be successfully retried, but in some scenarios not all of them are retriable, and the act of sending too many requests may already trip server-side DoS mitigations.

Since .NET 11 SocketsHttpHandler has a new heuristic where we'll remember the last advertised stream limit for a given host, and avoid exceeding it on future connections. This solves the issue when the server advertises a consistent low limit on all connections, but does nothing for situations where the stream limit is dynamic on every individual connection.

I'm proposing we expose an API which allows you to configure the initial stream limit, and we'll use that for new connections.
If it's not set we'll fall back to the heuristic, and if we haven't observed a SETTINGS frame yet, to 100, as we do today.

The proposed property is nullable to distinguish between the property being set manually vs. using our own internal default of 100.
The setting name from the spec is SETTINGS_MAX_CONCURRENT_STREAMS.

API Proposal

namespace System.Net.Http;

public partial class SocketsHttpHandler
{
    // Existing
    // public int InitialHttp2StreamWindowSize { get; set; }
    // public bool EnableMultipleHttp2Connections { get; set; }

    public int? InitialHttp2MaxConcurrentStreams { get; set; }
}

API Usage

var handler = new SocketsHttpHandler();

// Start with 1, making it impossible to exceed the server limit.
// Concurrency will adjust up automatically once the real server limit is received.
handler.InitialHttp2MaxConcurrentStreams = 1;

Alternative Designs

Expose the knob via AppContext/environment variables instead.

Risks

No response

Activity

  1. added this to the 12.0.0 milestone on Aug 18, 2026
  2. added
    api-suggestion
    on Aug 18, 2026
  3. dotnet-policy-service commented on Aug 18, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @karelz, @dotnet/ncl
    See info in area-owners.md if you want to be subscribed.

  4. modified the milestones: 12.0.0, 11.0.0 on Aug 18, 2026
  5. added
    api-ready-for-review
    and removed
    api-suggestion
    on Aug 18, 2026
  6. bartonjs commented on Aug 18, 2026

    @bartonjs
    Member

    Video

    • After a very long debate, we removed the question mark, and the property will default to the implementation value 100.
    namespace System.Net.Http;
    
    public partial class SocketsHttpHandler
    {
        public int InitialHttp2MaxConcurrentStreams { get; set; }
    }
  7. modified the milestones: 11.0.0, 12.0.0 on Aug 18, 2026
  8. added
    api-approved
    and removed
    api-ready-for-review
    on Aug 18, 2026
  9. added a commit that references this issue on Aug 26, 2026
    b2a6bda
  10. MihaZupan commented on Aug 26, 2026

    @MihaZupan
    MemberAuthor

    Implemented for .NET 12 in #132521, and backported to .NET 11 RC2 in #132566.

  11. locked and limited conversation to collaborators on Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-approvedarea-System.Net.Http

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions