Repository navigation
Make post-GC and post-dispose HandleDictionary test assertions address-reuse safe - #5475
Conversation
|
📖 Documentation Preview Add the Removing the label removes the preview. While the label is present, each new commit updates it. This comment is automatically updated by the documentation staging workflow. |
📦 Try the packages from this PRWarning 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 -- 5475PowerShell / Windows: iex "& { $(irm https://raw.githubusercontent.com/mono/SkiaSharp/main/scripts/get-skiasharp-pr.ps1) } 5475"Step 2 — Add the local NuGet source dotnet nuget add source ~/.skiasharp/hives/pr-5475/packages --name skiasharp-pr-5475More options
Or download manually from Azure Pipelines — look for the Remove the source when you're done: dotnet nuget remove source skiasharp-pr-5475 |
|
@dalexsoto review |
📊 SkiaSharp benchmarks — PR #5475⭐ this PR (full source build) vs 🌙 nightly · Linux · Windows · macOS
Highlights⏱️ Time — 🔴 25 slower · 🟢 24 faster
Full per-OS benchmark deltasLinux⏱️ Time (vs 🌙 nightly
Windows⏱️ Time (vs 🌙 nightly
macOS⏱️ Time (vs 🌙 nightly
|
|
@dalexsoto review |
261f76a to
a9cb45e
Compare
Move unknown-length chunk ownership into a shared ref struct inspired by segmented array builders. Keep the first descriptor inline and append pooled metadata segments without copying old entries. Preserve bounded payload chunks, unsigned lengths, ordered enumeration and exception-safe ownership. Use pattern-based using declarations, file-scoped namespaces and short method comments. Add 18 unit cases for partial writes, segment boundaries, invalid advances, rent failures and idempotent disposal. Preserve the previous collector in benchmarks; repeated comparisons show comparable throughput with unchanged warm managed allocations. Full-solution runs still intermittently encounter pre-existing stale-native-address assertions tracked separately by #5475; no checks or tests were weakened. Co-authored-by: Copilot App <[email protected]>
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed all 9 changed test and helper files with their registry, weak-reference, wrapper-ownership and fixture integration, including a separate final blocker search. Identity-aware assertions tolerate native address reuse while preserving original-wrapper collection and deregistration checks. Native address reuse is permitted without weakening original-wrapper deregistration or collection checks; author-reported suite results are not independently executed validation. No independent high-confidence blocker remains in this bounded static review; no executed runtime or whole-pipeline certification is claimed.
…se safe Co-authored-by: Copilot App <[email protected]>
…registry checks Co-authored-by: Copilot App <[email protected]>
…Collected Co-authored-by: Copilot App <[email protected]>
…alizer draining Co-authored-by: Copilot App <[email protected]>
…ertDeregistered Co-authored-by: Copilot App <[email protected]>
cce6c47 to
5700d75
Compare
Move unknown-length chunk ownership into a shared ref struct inspired by segmented array builders. Keep the first descriptor inline and append pooled metadata segments without copying old entries. Preserve bounded payload chunks, unsigned lengths, ordered enumeration and exception-safe ownership. Use pattern-based using declarations, file-scoped namespaces and short method comments. Add 18 unit cases for partial writes, segment boundaries, invalid advances, rent failures and idempotent disposal. Preserve the previous collector in benchmarks; repeated comparisons show comparable throughput with unchanged warm managed allocations. Full-solution runs still intermittently encounter pre-existing stale-native-address assertions tracked separately by #5475; no checks or tests were weakened. Co-authored-by: Copilot App <[email protected]>
dalexsoto
left a comment
There was a problem hiding this comment.
Reviewed all 9 changed test and helper files with their registry, weak-reference, wrapper-ownership and fixture integration, including a separate final blocker search. Identity-aware assertions tolerate native address reuse while preserving original-wrapper collection and deregistration checks. Native address reuse is permitted without weakening original-wrapper deregistration or collection checks; author-reported suite results are not independently executed validation. No independent high-confidence blocker remains in this bounded static review; no executed runtime or whole-pipeline certification is claimed.
Move unknown-length chunk ownership into a shared ref struct inspired by segmented array builders. Keep the first descriptor inline and append pooled metadata segments without copying old entries. Preserve bounded payload chunks, unsigned lengths, ordered enumeration and exception-safe ownership. Use pattern-based using declarations, file-scoped namespaces and short method comments. Add 18 unit cases for partial writes, segment boundaries, invalid advances, rent failures and idempotent disposal. Preserve the previous collector in benchmarks; repeated comparisons show comparable throughput with unchanged warm managed allocations. Full-solution runs still intermittently encounter pre-existing stale-native-address assertions tracked separately by #5475; no checks or tests were weakened. Co-authored-by: Copilot App <[email protected]>
Move unknown-length chunk ownership into a shared ref struct inspired by segmented array builders. Keep the first descriptor inline and append pooled metadata segments without copying old entries. Preserve bounded payload chunks, unsigned lengths, ordered enumeration and exception-safe ownership. Use pattern-based using declarations, file-scoped namespaces and short method comments. Add 18 unit cases for partial writes, segment boundaries, invalid advances, rent failures and idempotent disposal. Preserve the previous collector in benchmarks; repeated comparisons show comparable throughput with unchanged warm managed allocations. Full-solution runs still intermittently encounter pre-existing stale-native-address assertions tracked separately by #5475; no checks or tests were weakened. Co-authored-by: Copilot App <[email protected]>
Move unknown-length chunk ownership into a shared ref struct inspired by segmented array builders. Keep the first descriptor inline and append pooled metadata segments without copying old entries. Preserve bounded payload chunks, unsigned lengths, ordered enumeration and exception-safe ownership. Use pattern-based using declarations, file-scoped namespaces and short method comments. Add 18 unit cases for partial writes, segment boundaries, invalid advances, rent failures and idempotent disposal. Preserve the previous collector in benchmarks; repeated comparisons show comparable throughput with unchanged warm managed allocations. Full-solution runs still intermittently encounter pre-existing stale-native-address assertions tracked separately by #5475; no checks or tests were weakened. Co-authored-by: Copilot App <[email protected]>
Move unknown-length chunk ownership into a shared ref struct inspired by segmented array builders. Keep the first descriptor inline and append pooled metadata segments without copying old entries. Preserve bounded payload chunks, unsigned lengths, ordered enumeration and exception-safe ownership. Use pattern-based using declarations, file-scoped namespaces and short method comments. Add 18 unit cases for partial writes, segment boundaries, invalid advances, rent failures and idempotent disposal. Preserve the previous collector in benchmarks; repeated comparisons show comparable throughput with unchanged warm managed allocations. Full-solution runs still intermittently encounter pre-existing stale-native-address assertions tracked separately by #5475; no checks or tests were weakened. Co-authored-by: Copilot App <[email protected]>
Move unknown-length chunk ownership into a shared ref struct inspired by segmented array builders. Keep the first descriptor inline and append pooled metadata segments without copying old entries. Preserve bounded payload chunks, unsigned lengths, ordered enumeration and exception-safe ownership. Use pattern-based using declarations, file-scoped namespaces and short method comments. Add 18 unit cases for partial writes, segment boundaries, invalid advances, rent failures and idempotent disposal. Preserve the previous collector in benchmarks; repeated comparisons show comparable throughput with unchanged warm managed allocations. Full-solution runs still intermittently encounter pre-existing stale-native-address assertions tracked separately by #5475; no checks or tests were weakened. Co-authored-by: Copilot App <[email protected]>
Description
During parallel xUnit runs of
SkiaSharp.Tests.dll, tests that free a native object viaDispose()orCollectGarbage()and then assertAssert.False(SKObject.GetInstance<TDerived>(handle, out _))intermittently fail when a concurrent test thread allocates a new native object at the same freed pointer (mallocABA address reuse):THROW_OBJECT_EXCEPTIONS(Debug builds),HandleDictionary.GetInstanceNoLocks<TDerived>throwsInvalidOperationException: A managed object exists for the handle, but is not the expected typewhen a live owning wrapper of a different type occupieshandle.GetInstance<TDerived>returnstrue, causingAssert.Falseto fail.DoWorkinStreamLosesOwnershipAndCanBeGarbageCollectedandStreamIsReferencedAndNotDisposedPrematurely, the owningcodec,typeface, ordocumentcould become eligible for collection before the finalSKObject.GetInstanceassertion on the child stream without an explicitGC.KeepAlive.This PR:
SKHandleDictionaryTestHelpers.AssertDeregisteredto assertinstance.IsDisposedandinstance.Handle == IntPtr.Zero, and inspectHandleDictionary.instancesdirectly underinstancesLockso a disposed wrapper left in the dictionary is caught while a concurrent test reusing the freed pointer does not cause a false failure.SKHandleDictionaryTestHelpers.Track,AssertCollected, andCollectGarbageAndAssertCollectedAsyncto capture the wrapper's handle andHandleDictionary.instancesWeakReferenceregistration token while alive, strictly assertinstance.Target is nullafter GC, and verify that the original registration entry was removed fromHandleDictionary.instancesby finalization/disposal.SKObject.GetInstance<TDerived>assertions inSKCodecTest,SKTypefaceTest,SKManagedStreamTest,SKManagedWStreamTest,SKDocumentTest,SKFontManagerTest,SKImageTest, andSKRuntimeEffectTestto useAssertDeregistered,Track,AssertCollected, andCollectGarbageAndAssertCollectedAsync, with[MethodImpl(MethodImplOptions.NoInlining)]on helper methods andGC.KeepAliveon the owning object insideDoWork.Related issues
Fixes #
Required skia PR
None.
Areas affected
binding/)externals/skia/src/c,include/c)Changes
None — test-only changes, no public API or behavior change.
Testing
Ran the full console test suite on macOS ARM64 (
net10.0):dotnet cake --target=externals-download— passeddotnet build tests/SkiaSharp.Tests.Console.slnx -t:Rebuild -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0— passeddotnet test tests/SkiaSharp.Tests.Console.slnx -p:TargetFramework=net10.0 -p:TargetFrameworks=net10.0 --no-build— passed:SkiaSharp.Tests.dll: Passed: 6473, Failed: 0, Skipped: 23, Total: 6496SkiaSharp.Tests.SingletonInit.dll: Passed: 1, Failed: 0, Skipped: 0, Total: 1SkiaSharp.Gallery.Tests.Console.dll: Passed: 50, Failed: 0, Skipped: 0, Total: 50SkiaSharp.Vulkan.Tests.dll: Passed: 4, Failed: 0, Skipped: 21, Total: 25SkiaSharp.Direct3D.Tests.dll: Passed: 2, Failed: 0, Skipped: 3, Total: 5Checklist
Changesabove lists all public API and behavioral changes (or "None.")///documentation and regenerated bindings when applicablemono/skiaPR linked above and bindings regenerated