Skip to content

[release/11.0] Drain finalizers periodically in bestfit-finalize when multithreading is unsupported - #137273

Merged
lewing merged 1 commit into
release/11.0from
backport/pr-134996-to-release/11.0
Nov 10, 2026
Merged

lewing merged 1 commit into
release/11.0from
backport/pr-134996-to-release/11.0

Conversation

@github-actions

Copy link
Copy Markdown
Contributor

Backport of #134996 to release/11.0

/cc @lewing

Customer Impact

  • Customer reported
  • Found internally

[Select one or both of the boxes. Describe how this issue impacts customers, citing the expected and actual behaviors and scope of the issue. If customer-reported, provide the issue number.]

Regression

  • Yes
  • No

[If yes, specify when the regression was introduced. Provide the PR or commit if known.]

Testing

[How was the fix verified? How was the issue missed previously? What tests were added?]

Risk

[High/Medium/Low. Justify the indication by mentioning how risks were measured and addressed.]

IMPORTANT: If this backport is for a servicing release, please verify that:

  • For .NET 8 and .NET 9: The PR target branch is release/X.0-staging, not release/X.0.
  • For .NET 10+: The PR target branch is release/X.0 (no -staging suffix).

Package authoring no longer needed in .NET 9

IMPORTANT: Starting with .NET 9, you no longer need to edit a NuGet package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older versions.

… is unsupported (#134996)

Browser and WASI builds without multithreading have no finalizer thread,
so finalizers run from the host event loop (on browser,
`SystemJS_ScheduleFinalization` uses `setTimeout(..., 0)`).
`bestfit-finalize`'s `Go()` loop allocates requests synchronously and
never yields. As a result, no `Request` finalizer runs, the pinned
`GCHandle`s and survivor arrays of dead requests are never released, and
the test OOMs at ~3.8 GB.

When `RuntimeFeature.IsMultithreadingSupported` is false, the test now
calls `GC.WaitForPendingFinalizers()` once every `NumRequests`
iterations. That call drains pending finalizers synchronously. The
random sequence, allocation volume, pinning, and pass/fail conditions
are unchanged, and no explicit collections are added. Platforms that
support multithreading are unaffected.

This is a test workaround. It does not fix the runtime: any synchronous
allocation loop without a finalizer thread can starve finalizers the
same way.

**Validation**
- Desktop: compiled the test standalone and ran it with args `1 200
10000`. It passed.
- Browser/WASI: not run locally. In the issue, @tannergooding reproduced
the browser OOM and reported that the same drain workaround passed the
failing seed against the CI runtime.

Resolves #132107

> [!NOTE]
> This PR description was generated with GitHub Copilot.

---------

Co-authored-by: Copilot App <[email protected]>
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 3 pipeline(s).
12 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@lewing

lewing commented Nov 10, 2026

Copy link
Copy Markdown
Member

Test only change to make 11.0 ci greener

@lewing lewing added the Servicing-approved Approved for servicing release label Nov 10, 2026
@lewing
lewing enabled auto-merge (squash) November 10, 2026 19:17
@lewing

lewing commented Nov 10, 2026

Copy link
Copy Markdown
Member

cc @JulieLeeMSFT

@lewing

lewing commented Nov 10, 2026

Copy link
Copy Markdown
Member

/ba-g failures are known

@lewing
lewing merged commit 0be7d8e into release/11.0 Nov 10, 2026
100 of 103 checks passed
@lewing
lewing deleted the backport/pr-134996-to-release/11.0 branch November 10, 2026 23:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Infrastructure Servicing-approved Approved for servicing release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant