Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit the lock before we call into user code and handle losing the race for the RCW table #110828

Merged
merged 16 commits into from
Jan 7, 2025

Conversation

jkoritzinsky
Copy link
Member

@jkoritzinsky jkoritzinsky commented Dec 18, 2024

Fixes #110823

1. Register that we've created a managed object as a wrapper for a COM object first (equivalent to ExtObjCxtCache in CoreCLR)
2. Register the NativeObjectWrapper for lifetime management (equivalent to the sync-block interop info in CoreCLR).

This ensures that we have the same behavior as CoreCLR.
@jkoritzinsky
Copy link
Member Author

Tests for this specific deadlock are still TODO, but I've reorganized the code for the NativeAOT ComWrappers implementation to match the same order of logic as the CoreCLR implementation and encapsulated each step into separate helper functions (which also helped significantly clarify lock usage).

Copy link
Contributor

@Sergio0694 Sergio0694 left a comment

Choose a reason for hiding this comment

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

Thank you for adding all the comments!! 😄
Left a few more notes.

@jkoritzinsky jkoritzinsky marked this pull request as ready for review December 23, 2024 20:36
@jkoritzinsky
Copy link
Member Author

Validated that the ComWrappers tests pass locally and added a test for the deadlock. This is ready for review!

@AaronRobinsonMSFT
Copy link
Member

@jkoritzinsky Can you please run GCStress locally? Ideally we'd also include some amount of JITStress too. I'm also fine kicking off the legs that run too.

@jkoritzinsky
Copy link
Member Author

Do we have GCStress support for NativeAOT?

@AaronRobinsonMSFT
Copy link
Member

@jkoritzinsky Oh, right. I think we do, but we don't have a CI for it. @MichalStrehovsky Do we have a way to run GCStress on local native AOT?

@jkotas
Copy link
Member

jkotas commented Jan 6, 2025

There is no GC stress for native AOT.

@jkoritzinsky
Copy link
Member Author

/azp run runtime-nativeaot-outerloop

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@Sergio0694
Copy link
Contributor

Not exactly the same (although @EgorBo said it's kinda close enough? 😅), I've added an option in the Microsoft Store to simulate GC stress (I basically just spawn a thread that just spams GC.Collect(); Thread.Wait(50); in a loop). Perhaps it'd help if I also tested with that mode enabled for a bit, just to double check things don't blow up when that's running?

@jkoritzinsky
Copy link
Member Author

NativeAOT outerloop failures are unrelated. Can I get one more review pass?

@jkoritzinsky jkoritzinsky merged commit 0d1432e into dotnet:main Jan 7, 2025
113 of 116 checks passed
@jkoritzinsky jkoritzinsky deleted the no-createobject-lock branch January 7, 2025 03:48
Sergio0694 pushed a commit to Sergio0694/runtime that referenced this pull request Jan 7, 2025
@Sergio0694
Copy link
Contributor

Sergio0694 commented Jan 7, 2025

I tested with the Microsoft Store and everything seems to work fine:

I used the Store for a while, including closing and launching it a few times, with and without our "GC stress" mode enabled as well (which creates a thread that just spams GC.Collect() every 50 milliseconds in a loop). Couldn't find any issues 🎉

Could we backport this one too? I think it should be our last blocker from the NAOT side for shipping 😄
Thank you!

@jkoritzinsky
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

github-actions bot commented Jan 7, 2025

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/12654501932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hang during 'ComWrappers.TryGetOrCreateObjectForComInstanceInternal()' on Native AOT
4 participants