Oliver
Oliver

Reputation: 36413

ServicePointManager.DefaultConnectionLimit returning Int32.MaxValue

For diagnostics purposes I am logging ServicePointManager.DefaultConnectionLimit. However oddly enough it seems to be returning Int32.MaxValue (i.e 2147483647).

This seem to contradict the MSDN documentation on the subject:

The maximum number of concurrent connections allowed by a ServicePoint object. The default value is 2.

For context, I am getting this value in an ASP.Net 4 application running on 4.6.1

Upvotes: 3

Views: 3707

Answers (1)

Oliver
Oliver

Reputation: 36413

Based on @Wimmel's link it seems in ASP.Net that it is set to Int32.MaxValue as part of the HTTP Runtime.

We can see this by looking inside the System.Web assembly at the HttpRuntime class.

There is a method called SetAutoConfigLimits which sets it to Int32.MaxValue. Here is the relevant excerpt:

private void SetAutoConfigLimits(ProcessModelSection pmConfig)
{
    int workerThreads;
    int completionPortThreads;
    ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
    if (pmConfig.DefaultMaxWorkerThreadsForAutoConfig != workerThreads || pmConfig.DefaultMaxIoThreadsForAutoConfig != completionPortThreads)
        UnsafeNativeMethods.SetClrThreadPoolLimits(pmConfig.DefaultMaxWorkerThreadsForAutoConfig, pmConfig.DefaultMaxIoThreadsForAutoConfig, true);
    ServicePointManager.DefaultConnectionLimit = int.MaxValue;
}

Upvotes: 9

Related Questions