Skip to content

[coreclr] Throttling of parallel downloads is supported#124964

Closed
ilonatommy wants to merge 4 commits intodotnet:mainfrom
ilonatommy:fix-clr-throttling-124900
Closed

[coreclr] Throttling of parallel downloads is supported#124964
ilonatommy wants to merge 4 commits intodotnet:mainfrom
ilonatommy:fix-clr-throttling-124900

Conversation

@ilonatommy
Copy link
Member

@ilonatommy ilonatommy commented Feb 27, 2026

Fixes #124900.

Changes

  1. mono allowed strings, see:
    if (parallel_count == loaderHelpers.maxParallelDownloads) {
    but coreclr is stricter - only integers, see:
    if (currentParallelDownloads === loaderConfig.maxParallelDownloads) {

    We have to add conversion to integer in wbt main.js.

2) All webcil assemblies are "webcil10" type that is excluded from throttling in coreclr, see:

. We have to remove this entry.

  1. Mono does not fetch dotnetwasm through globalThis.fetch, it's loaded via import(). In CoreCLR dotnetwasm is fetched and the test counts it towards parallel downloads count, which increases it. We have to update the WBT expectations as well.

Has to wait for #124850 to be merged.

@ilonatommy ilonatommy self-assigned this Feb 27, 2026
@ilonatommy ilonatommy requested a review from maraf as a code owner February 27, 2026 12:37
Copilot AI review requested due to automatic review settings February 27, 2026 12:37
@ilonatommy ilonatommy added arch-wasm WebAssembly architecture area-Infrastructure-coreclr os-browser Browser variant of arch-wasm labels Feb 27, 2026
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes issue #124900 where max parallel downloads exceed the configured maximum in CoreCLR WASM. The issue stems from differences in how CoreCLR and Mono handle download throttling and WASM module loading.

Changes:

  • Removed "webcil10" from the noThrottleNoRetry exclusion list in CoreCLR, allowing webcil assemblies to be properly throttled
  • Added parseInt conversion for maxParallelDownloads in test harness to ensure CoreCLR receives a number type (not string)
  • Added CoreCLR-specific logic to exclude dotnet.native.wasm from fetch counting, matching Mono's behavior where it's loaded via import()
  • Updated test to pass runtime flavor information to differentiate between Mono and CoreCLR test expectations

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
src/native/libs/Common/JavaScript/loader/assets.ts Removes "webcil10" from noThrottleNoRetry map to enable proper throttling of webcil assemblies
src/mono/wasm/testassets/WasmBasicTestApp/App/wwwroot/main.js Adds parseInt conversion for maxParallelDownloads config and CoreCLR-specific fetch wrapper to exclude dotnet.native.wasm from download counting
src/mono/wasm/Wasm.Build.Tests/MaxParallelDownloadsTests.cs Passes runtime flavor to test to enable different behavior verification for Mono vs CoreCLR

BrowserQueryString: new NameValueCollection { {"maxParallelDownloads", maxParallelDownloads } }
BrowserQueryString: new NameValueCollection {
{"maxParallelDownloads", maxParallelDownloads },
{"runtimeFlavor", s_buildEnv.IsMonoRuntime ? "Mono" : "CoreCLR" }
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property s_buildEnv.IsMonoRuntime does not exist. The correct way to check the runtime flavor is to use EnvironmentVariables.RuntimeFlavor != "CoreCLR" (as seen in BuildEnvironment.cs line 114 and WasmTemplateTestsBase.cs line 127). Alternatively, consider adding a public property IsMonoRuntime to BuildEnvironment class that returns EnvironmentVariables.RuntimeFlavor != "CoreCLR" for better consistency and readability.

Suggested change
{"runtimeFlavor", s_buildEnv.IsMonoRuntime ? "Mono" : "CoreCLR" }
{"runtimeFlavor", EnvironmentVariables.RuntimeFlavor != "CoreCLR" ? "Mono" : "CoreCLR" }

Copilot uses AI. Check for mistakes.
}
};
dotnet.withConfig({ maxParallelDownloads: maxParallelDownloads });
dotnet.withConfig({ maxParallelDownloads: parseInt(maxParallelDownloads) });
Copy link

Copilot AI Feb 27, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The parseInt call should include a radix parameter (10) and handle potential NaN results. If maxParallelDownloads is null/undefined/invalid, parseInt returns NaN, which could cause unexpected behavior in the runtime throttling logic. Consider adding validation or using parseInt(maxParallelDownloads, 10) || 16 to provide a fallback to the default value.

Suggested change
dotnet.withConfig({ maxParallelDownloads: parseInt(maxParallelDownloads) });
dotnet.withConfig({ maxParallelDownloads: parseInt(maxParallelDownloads, 10) || 16 });

Copilot uses AI. Check for mistakes.
const isCoreCLR = params.get("runtimeFlavor") === "CoreCLR";
globalThis.fetch = async (...args) => {
if (isCoreCLR) {
const url = typeof args[0] === "string" ? args[0] : args[0]?.url ?? "";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please explain ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the changes are described in the PR, this is point 3.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. I think we do not use import() for .wasm files.

Copilot AI review requested due to automatic review settings March 2, 2026 08:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +34 to +37
BrowserQueryString: new NameValueCollection {
{"maxParallelDownloads", maxParallelDownloads },
{"runtimeFlavor", s_buildEnv.IsMonoRuntime ? "Mono" : "CoreCLR" }
}
Copy link

Copilot AI Mar 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description lists removing the webcil10 exemption from throttling in src/native/libs/Common/JavaScript/loader/assets.ts (the noThrottleNoRetry map), but in the current code that entry still appears to be present. If that change was intentionally deferred (e.g., due to Webcil loader concerns), please update the PR description accordingly; otherwise include the intended code change so the description matches what this PR actually does.

Copilot uses AI. Check for mistakes.
@ilonatommy
Copy link
Member Author

In favor of #124969.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arch-wasm WebAssembly architecture area-Infrastructure-coreclr os-browser Browser variant of arch-wasm

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

[coreclr] Max parallel downloads exceeds the maximum

3 participants