Skip to content

Fix x86 .NET Framework threading test OOM failures (#3608) - #3674

Merged
mattleibow merged 1 commit into
mainfrom
dev/issue-3608-fix-x86-threading-tests
Apr 26, 2026
Merged

mattleibow merged 1 commit into
mainfrom
dev/issue-3608-fix-x86-threading-tests

Conversation

@mattleibow

Copy link
Copy Markdown
Contributor

Investigation: Fix x86 .NET Framework threading test OOM (#3608)

Problem

Two multithreading tests fail consistently on Windows .NET Framework x86 (net472-x86) with Unable to allocate pixels for the bitmap due to x86 2GB address space exhaustion. Hits 8/15 recent main builds (53%).

Related Issues

Fixes #3608

@mattleibow mattleibow added the copilot Created by GitHub Copilot label Apr 15, 2026
@github-actions

github-actions Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

📦 Try the packages from this PR

Warning

Do not run these scripts without first reviewing the code in this PR.

Step 1 — Download the packages

bash / macOS / Linux:

curl -fsSL https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.sh | bash -s -- 3674

PowerShell / Windows:

iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 3674"

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-3674/packages --name skiasharp-pr-3674
More options
Option Description
--successful-only / -SuccessfulOnly Only use successful builds
--force / -Force Overwrite previously downloaded packages
--list / -List List available artifacts without downloading
--build-id ID / -BuildId ID Download from a specific build

Or download manually from Azure Pipelines — look for the nuget artifact on the build for this PR.

Remove the source when you're done:

dotnet nuget remove source skiasharp-pr-3674

github-actions Bot pushed a commit that referenced this pull request Apr 15, 2026
@github-actions

github-actions Bot commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

📖 Documentation Preview

The documentation for this PR has been deployed and is available at:

🔗 View Staging Site
🔗 View Staging Docs
🔗 View Staging Gallery

This preview will be updated automatically when you push new commits to this PR.


This comment is automatically updated by the documentation staging workflow.

@mattleibow
mattleibow marked this pull request as ready for review April 15, 2026 12:44
github-actions Bot pushed a commit that referenced this pull request Apr 15, 2026
@mattleibow
mattleibow force-pushed the dev/issue-3608-fix-x86-threading-tests branch from 41e7576 to b558338 Compare April 15, 2026 14:02
github-actions Bot pushed a commit that referenced this pull request Apr 15, 2026
@mattleibow
mattleibow force-pushed the dev/issue-3608-fix-x86-threading-tests branch 9 times, most recently from ed50375 to cec90da Compare April 16, 2026 00:27
github-actions Bot pushed a commit that referenced this pull request Apr 16, 2026
@mattleibow
mattleibow force-pushed the dev/issue-3608-fix-x86-threading-tests branch from cec90da to 7d7b6c9 Compare April 16, 2026 01:53
github-actions Bot pushed a commit that referenced this pull request Apr 16, 2026
@mattleibow mattleibow added the upgrading/4.x Issues and discussions relating to the upgrade from 3.x to 4.x label Apr 16, 2026
@mattleibow mattleibow added this to the 4.x Preview 1 milestone Apr 16, 2026
@mattleibow
mattleibow force-pushed the dev/issue-3608-fix-x86-threading-tests branch from 18d641d to 31a55e0 Compare April 24, 2026 03:07
On x86 (.NET Framework), address space is limited to 2GB. The
(100 threads × 1000 iterations) and (1000 iterations) stress tests
create too many undisposed native allocations simultaneously, causing
the GC finalizer queue to fall behind and Skia's allocator to fail.

Fix: skip the known-OOM combinations on x86, and add lighter-weight
intermediate variants (10×100 and 100 iterations) so concurrent
GC/finalizer behavior is still exercised at lower load.

Co-authored-by: Copilot <[email protected]>
@mattleibow
mattleibow force-pushed the dev/issue-3608-fix-x86-threading-tests branch from 31a55e0 to a8c73f4 Compare April 24, 2026 03:08
github-actions Bot pushed a commit that referenced this pull request Apr 24, 2026
@mattleibow
mattleibow merged commit a183e05 into main Apr 26, 2026
5 of 6 checks passed
@mattleibow
mattleibow deleted the dev/issue-3608-fix-x86-threading-tests branch April 26, 2026 13:24
github-actions Bot pushed a commit that referenced this pull request Apr 26, 2026
mattleibow added a commit that referenced this pull request May 30, 2026
Backport of #3674 to release/3.119.x.

SKBitmapThreadingTest.ImageScalingMultipleThreadsTest and
SKObjectTest.EnsureMultithreadingDoesNotThrow intentionally create native
SkiaSharp objects WITHOUT disposing them, so they are reclaimed only by the
GC and finalizer thread. This is deliberate: the tests verify that SkiaSharp
objects can be finalized safely from many threads concurrently. Adding
deterministic disposal would defeat the purpose of the tests.

On x86 (.NET Framework, 2GB address space) the heaviest variants queue too
many undisposed native allocations for the finalizer to keep up, so Skia's
allocator fails ("Unable to allocate pixels"). This is a genuine
address-space limit, not a leak: the 64-bit .NET Core jobs pass.

Fix (matching main): skip the known-OOM combinations on x86 and add lighter
intermediate variants (10x100 and 100) so concurrent GC/finalizer behavior
is still exercised at lower load. Also add comments documenting the test
purpose and that disposal is intentionally omitted.

Co-authored-by: Copilot <[email protected]>
mattleibow added a commit that referenced this pull request Jun 2, 2026
Fix x86 .NET Framework threading test OOM failures (#4105)

Backport of #3674 to release/3.119.x.
Fixes #3608

Context: #3674
Fixes: chronically-red "Windows (.NET Framework)" (net48/x86) Tests job on release/3.119.x

The internal Tests pipeline on release/3.119.x has been red for months.
The failing job is Windows (.NET Framework) on x86, where
SKBitmapThreadingTest.ImageScalingMultipleThreadsTest(100, 1000) and
SKObjectTest.EnsureMultithreadingDoesNotThrow(1000) throw "Unable to
allocate pixels for the bitmap", with adjacent tests dying as collateral
in the same starved process.

These tests intentionally create native SkiaSharp objects without
disposing them so they are reclaimed only by the GC and finalizer thread
— that is the point of the tests: they verify SkiaSharp objects can be
finalized safely from many threads concurrently. Disposing would defeat
the purpose (an earlier "add using" attempt was wrong and was reverted).
The real cause is an environment limit: on x86 (.NET Framework, 2 GB
address space) the heaviest variants queue more undisposed native
allocations than the finalizer can keep pace with, so Skia's allocator
fails. The 64-bit .NET Core jobs have enough address space and pass.

  * Skip the known-OOM combinations on x86 only (IntPtr.Size == 4) — a
    sanctioned environment skip, not masking a product bug.
  * Add lighter intermediate variants (10x100 and 100) so concurrent
    GC/finalizer behavior is still exercised on x86 at lower load.
  * Document the test purpose and that disposal is intentionally omitted,
    so future readers don't "fix" it by adding using.

Touches tests only:
tests/SkiaSharp.Tests.Console/SkiaSharp/SKBitmapThreadingTest.cs and
tests/Tests/SkiaSharp/SKObjectTest.cs (+28/-0).

Validated by a full pipeline run that built natives fresh in-run
(3.119.5-preview.0.3+merge): all stages succeeded, including every
Tests-stage job. The previously chronically-red net48/x86 job now passes.

Co-authored-by: Copilot <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

copilot Created by GitHub Copilot upgrading/4.x Issues and discussions relating to the upgrade from 3.x to 4.x

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

Flaky CI: x86 .NET Framework tests fail with memory exhaustion under heavy threading

1 participant