ServicePointManager.DefaultConnectionLimit returning Int32.MaxValue

十年热恋 提交于 2019-12-19 10:16:27

问题


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


回答1:


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;
}


来源:https://stackoverflow.com/questions/36792608/servicepointmanager-defaultconnectionlimit-returning-int32-maxvalue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!