Skip to content

Keep COM test composition variable alive through end of scope. - #15223

Merged
Shyam-Gupta merged 1 commit into
mainfrom
mmitche-fix-com-test-lifetime
Oct 2, 2026
Merged

Shyam-Gupta merged 1 commit into
mainfrom
mmitche-fix-com-test-lifetime

Conversation

@mmitche

@mmitche mmitche commented Oct 2, 2026 •

Copy link
Copy Markdown
Member

Fixes #

Proposed changes

  • Keep the Composition instance in TryGetIStreamData_DoesNotDoubleReleaseStream reachable through the final unmanaged refcount assertion.
  • Add GC.KeepAlive(composition) at the intended liveness boundary; no production COM ownership or release logic changes.
  • GC.KeepAlive(obj) intentionally tells the JIT/GC that obj remains reachable through the call. It does not read or modify the object, dispose it, allocate a GCHandle, permanently root it, extend its lifetime beyond the call, or force immediate collection/finalization afterward. Here it keeps Composition, its adapters, and their AgileComPointer fields reachable, preventing finalizers from revoking GIT entries and releasing two COM references before the assertion. Normal collection and finalization may occur after the call, so cleanup semantics are unchanged.

Customer Impact

  • Removes a net481/x86 test flake caused by the JIT considering composition dead before the test's final native refcount probe.
  • No product behavior changes.

Regression?

  • No

Risk

  • Low. This is a test-only managed-lifetime boundary with no production code changes.

Test methodology

  • Passed the exact net481/x86 test:
    $env:DOTNET_ROOT = "$PWD\.dotnet"; $env:PATH = "$PWD\.dotnet;$env:PATH"; & .\.dotnet\dotnet.exe test .\src\System.Private.Windows.Core\tests\System.Private.Windows.Core.Tests\System.Private.Windows.Core.Tests.csproj -f net481 -p:TargetArchitecture=x86 -- --filter-method "System.Private.Windows.Ole.NativeToManagedAdapterTests.TryGetIStreamData_DoesNotDoubleReleaseStream"
  • Result: Passed, 1 total / 1 succeeded / 0 failed / 0 skipped; the runner reported (net48|x86).

Test environment(s)

  • Windows 10.0.26200; .NET SDK 11.0.100-rc.1.26420.103; x86 test process targeting net481.
Microsoft Reviewers: Open in CodeFlow

@mmitche mmitche changed the title Keep COM test composition alive Keep COM test composition variable alive through end of scope. Oct 2, 2026
@mmitche
mmitche marked this pull request as ready for review October 2, 2026 18:47
@mmitche
mmitche requested a review from a team as a code owner October 2, 2026 18:47
@mmitche
mmitche requested a review from premun October 2, 2026 18:47
@codecov

codecov Bot commented Oct 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 37.84861%. Comparing base (f055ed4) to head (2b25000).

Additional details and impacted files
@@              Coverage Diff              @@
##                main      #15223   +/-   ##
=============================================
  Coverage   37.84861%   37.84861%           
=============================================
  Files            246         246           
  Lines           9789        9789           
  Branches        1031        1031           
=============================================
  Hits            3705        3705           
  Misses          5920        5920           
  Partials         164         164           
Flag Coverage Δ
Debug 37.84861% <ø> (ø)
production 40.04608% <ø> (ø)
test 20.64923% <ø> (ø)
unit 40.04608% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Shyam-Gupta Shyam-Gupta left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @mmitche

@Shyam-Gupta
Shyam-Gupta merged commit a84cf1f into main Oct 2, 2026
10 checks passed
@Shyam-Gupta
Shyam-Gupta deleted the mmitche-fix-com-test-lifetime branch October 2, 2026 19:25
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Oct 3, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 2, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants