Repository navigation
[ImageIO] Keep metadata alive while enumerating tags. Fixes #26545 - #26676
Conversation
EnumerateTags passes only the native handle to ImageIO. Once that handle has been read, an optimizing runtime can collect the managed metadata owner while native enumeration is still in progress. Its finalizer can then release metadata needed by subsequent callbacks, which is consistent with the intermittent NativeAOT tag-retain crash. Keep the owner alive until native enumeration returns. Add forced-GC coverage for full enumeration and early termination, checking the managed owner's weak reference. Retain the native metadata independently in the tests so a lifetime regression produces an assertion failure rather than a native crash. Fixes #26545 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
Only a minor test naming nit remains; no blocking issues were identified.
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
Fixes a CGImageMetadata lifetime issue during native tag enumeration and adds forced-GC regression coverage.
Changes:
- Keeps the managed metadata owner alive through enumeration.
- Tests complete and early-terminated enumeration under forced GC.
- Retains native metadata independently in tests.
- Minor nit: clarify the ambiguous test name
EnumerateMetadataWithCollection.
| File | Description |
|---|---|
tests/monotouch-test/CoreGraphics/CGImageMetadataTests.cs |
Adds lifetime regression tests. |
src/ImageIO/CGImageMetadata.cs |
Preserves metadata owner lifetime during enumeration. |
Rename EnumerateMetadataWithCollection to EnumerateMetadataWithForcedGC so the test name describes its garbage-collection lifetime scenario rather than suggesting collection traversal. Both existing test cases and their assertions remain unchanged. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
🚀 [CI Build #967512d] Test results 🚀Test results✅ All tests passed on VSTS: test results. 🎉 All 269 tests passed 🎉 Tests counts✅ assembly-processing: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
…ng tags. Fixes #26545 (#26713) EnumerateTags passes only the native handle to ImageIO. Once that handle has been read, an optimizing runtime can collect the managed metadata owner while native enumeration is still in progress. Its finalizer can then release metadata needed by subsequent callbacks, which is consistent with the intermittent NativeAOT tag-retain crash. Keep the owner alive until native enumeration returns. Add forced-GC coverage for full enumeration and early termination, checking the managed owner's weak reference. Retain the native metadata independently in the tests so a lifetime regression produces an assertion failure rather than a native crash. Fixes #26545 🤖 Pull request created by Copilot Backport of #26676. --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
#26704) ## Summary Follow up on the lifetime audit prompted by #26545 and #26676. Native enumeration receives only the owner's handle; rooting the callback does not necessarily keep its managed owner alive while callbacks allocate or trigger GC. Add 37 `GC.KeepAlive (this)` guards after synchronous native calls: the 29 additional enumerators identified by the audit, font sorting, pre-shared-key access, and six adjacent callback operations. Preserve native return values and keep owners alive before callback state is released. The ImageIO fix in #26676 is not duplicated. Fix `DispatchQueue.Submit` by retaining its callback/owner tuple until all iterations finish, freeing the handle once in `finally`, and using the matching `Action<int>` delegate type. Correct related defects encountered while exercising these APIs: native boolean callback return types, borrowed metadata ownership, peer certificate conversion, the signature-algorithm success check, pre-shared-key delegate/ownership handling, and recursive WebSocket response header forwarding. ## Coverage Add forced-GC regressions for path application, caret enumeration (full traversal and early termination), all four tag collection operations, and serial/concurrent dispatch iterations. The path, line, and tag tests independently retain native owners so regressions fail assertions instead of crashing. Add or extend functional coverage for browse-result interfaces, prohibited interface objects, content-context metadata, establishment-report protocols, WebSocket response headers, Security metadata accessors, and connection batching. WebSocket request enumeration and framer parsing tests remain deferred: their existing public callback APIs require separate native return-contract corrections. Optional TLS collections are checked when available, and the existing fixture does not provide a TLS-PSK server to exercise actual PSK callbacks. 🤖 Pull request created by Copilot --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

EnumerateTags passes only the native handle to ImageIO. Once that handle has been read, an optimizing runtime can collect the managed metadata owner while native enumeration is still in progress. Its finalizer can then release metadata needed by subsequent callbacks, which is consistent with the intermittent NativeAOT tag-retain crash.
Keep the owner alive until native enumeration returns. Add forced-GC coverage for full enumeration and early termination, checking the managed owner's weak reference. Retain the native metadata independently in the tests so a lifetime regression produces an assertion failure rather than a native crash.
Runtime confirmation is deferred to CI: Xcode 27 is unavailable locally, and the clean build was stopped during dependency restore.
Fixes #26545
🤖 Pull request created by Copilot