Skip to content

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

Merged
mattleibow merged 1 commit into
release/3.119.xfrom
mattleibow/fix-release-3119-bitmap-tests
Jun 2, 2026
Merged

mattleibow merged 1 commit into
release/3.119.xfrom
mattleibow/fix-release-3119-bitmap-tests

Conversation

@mattleibow

@mattleibow mattleibow commented May 30, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The internal Tests pipeline on release/3.119.x has been chronically red. The failing job is Windows (.NET Framework) (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 process.

Root cause (corrected)

These tests intentionally create native SkiaSharp objects without disposing them, so they are reclaimed only by the GC and finalizer thread. That is the whole point of the tests — they verify SkiaSharp objects can be finalized safely from many threads concurrently. Disposing would defeat the purpose, so an earlier "add using" approach was wrong and has been reverted.

The real issue is a genuine environment limit: on x86 (.NET Framework, 2 GB address space) the heaviest variants queue too many undisposed native allocations for the finalizer to keep pace, so Skia's allocator fails. The 64-bit .NET Core jobs have enough address space and pass.

Fix

This is a backport of #3674 (already on main):

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

Files: tests/SkiaSharp.Tests.Console/SkiaSharp/SKBitmapThreadingTest.cs, tests/Tests/SkiaSharp/SKObjectTest.cs.

Validation

  • Compared with main's fix (Fix x86 .NET Framework threading test OOM failures (#3608) #3674) and matched its approach exactly.
  • Built correct 119.x natives locally and ran both tests (all variants) — Passed: 6, Failed: 0, Skipped: 0 on 64-bit (the x86 skip can't trigger locally on arm64).
  • CI is now green. A full pipeline run that built natives fresh in-run (build 3.119.5-preview.0.3+merge) completed with all stages succeeded, including every Tests-stage job. Most importantly, the previously chronically-red Windows (.NET Framework) (net48/x86) job now passes — confirming the fix on the only environment that can reproduce the address-space exhaustion.

Note: standard release PR pre-merge builds cannot go green on this branch due to a pre-existing CI bootstrap issue unrelated to this change (they download pre-built natives from the last succeeded release branch build, of which there are none). Builds that compile natives in-run (branch builds and the manual merge build above) validate the fix correctly. Merging this PR restores a green native-artifact source for the branch.

Co-authored-by: Copilot [email protected]

@github-actions

github-actions Bot commented May 30, 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 -- 4105

PowerShell / Windows:

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

Step 2 — Add the local NuGet source

dotnet nuget add source ~/.skiasharp/hives/pr-4105/packages --name skiasharp-pr-4105
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-4105

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
mattleibow force-pushed the mattleibow/fix-release-3119-bitmap-tests branch from ac5a352 to ad0a4d3 Compare May 30, 2026 18:31
@mattleibow mattleibow changed the title Fix native memory exhaustion in SKBitmapThreadingTest on net48 Fix x86 .NET Framework threading test OOM failures (backport #3674) May 30, 2026
@mattleibow
mattleibow merged commit 625589e into release/3.119.x Jun 2, 2026
2 of 3 checks passed
@mattleibow
mattleibow deleted the mattleibow/fix-release-3119-bitmap-tests branch June 2, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant