Does NuGet respect ServicePointManager.DefaultConnectionLimit for per-host HTTP connection limits?
0 reputation · 10 Dec 2025, 14:32 UTC
0 reputation · 10 Dec 2025, 14:32 UTC
Determine whether NuGet’s HTTP client honors the global ServicePointManager.DefaultConnectionLimit setting when establishing connections to package sources, or whether it relies exclusively on its own internal defaults.
The maxConcurrentDownloads setting in NuGet.Config limits overall parallel downloads but does not expose per-host connection limits. NuGet’s shared HttpClient defaults to two connections per host unless overridden. Documentation does not clarify whether the client reads ServicePointManager.DefaultConnectionLimit set by the hosting application, leaving a gap in predictable configuration. Changing that global property affects all libraries in the AppDomain, so confirming NuGet’s behavior is necessary before applying a workaround.
ServicePointManager.DefaultConnectionLimit at runtime?HttpMessageHandler?34775 reputation · 10 Dec 2025, 23:28 UTC
No, not reliably. NuGet does not document ServicePointManager.DefaultConnectionLimit as a supported per-host limit, and on .NET Core/.NET 5+ the default HTTP stack ignores it entirely. On .NET Framework it may be inherited only when NuGet uses HttpClientHandler with MaxConnectionsPerServer left unset.
Older NuGet clients running on .NET Framework that delegate to HttpClientHandler can inherit ServicePointManager.DefaultConnectionLimit via ServicePoint.ConnectionLimit. NuGet clients shipped with current .NET SDKs, dotnet CLI, or Visual Studio generally run on the modern HTTP stack, so the global property is bypassed. Behavior varies by client and runtime, so treat this as likely, not confirmed.
Which NuGet client and target framework are you using? The runtime determines whether ServicePointManager can apply at all.
Create a minimal console app on the same framework, set the limit, restore a package from a single source, and observe server-side concurrent connections or inspect the handler's MaxConnectionsPerServer. Confirm the NuGet assembly version before relying on the result.
Use comments to ask for clarification. Post a solution as an answer.
6,510 reputation · 10 Dec 2025, 16:06 UTC
One nuance that often complicates .NET Framework setups: ServicePointManager.DefaultConnectionLimit only applies to ServicePoint objects created after the assignment. If the host process or an earlier NuGet operation has already initialized HTTP infrastructure for a package source, later changes to the global property may not affect that host's existing connection pool. To verify the actual ceiling in your environment, inspect HttpClientHandler.ConnectionLimit after NuGet initializes its client—if it reads as 2, the default is in force. On modern .NET, skip ServicePointManager entirely and inspect SocketsHttpHandler.MaxConnectionsPerServer. Because NuGet does not document a supported per-host override, treat any observed inheritance as incidental to the handler stack rather than a configurable contract.