-
Notifications
You must be signed in to change notification settings - Fork 1k
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
manually release ITypeInfo references #3315
Conversation
/cc @hughbe @RussKie @JeremyKuhne Instead of doing try/finally blocks I experimented with a disposable struct, tell me what you think. If you don't like it I can fall back to implementing this via try/finally blocks. |
src/System.Windows.Forms.Primitives/tests/Interop/Oleaut32/ITypeInfoTests.cs
Show resolved
Hide resolved
Also, fixes #3271 |
#3271 also happens in IPictureTests and I didn't touch those yet. Those tests aren't using ITypeInfo so I'm not sure if #3271 is the same issue. I'd leave it open for now. (The error in #3271 is not coming from the ITypeInfo instance, but from the IDispatch instance. Adding manual release for the IDispatch objects isn't going to have the same impact as for ITypeInfo because the images themselves are not shared between tests, only their type info is.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cheers thanks.
Just to confirm, is this specific to ITypeInfo? I think we should somehow have tests in dotnet/runtime verifying this behaviour.
Surely others will run into this somehow? Does this happen in netfx
Is |
Don’t think so. I have noticed some flakiness surrounding ImageList tests with handles in the past |
Its specific to unmanaged COM objects shared across multiple STA threads (ITypeInfo happens to be shared on the native side according to your linked discussion)
You need to have mutliple STA threads starting up/shutting down, this is not a common scenario, and if you have it you run into a lot of other problems (for example SystemEvents not dealing gracefully with it, WinForms itself doesn't deal gracefully with it, WPF has a few issues posted). From what I can tell having multiple STA threads starting and terminating needs more work across the whole framework before it can work reliably. And I don't think the old COM interop is going to get any fixes in this area.
The best you could do is verify that the bug still exists? I think the point is that the behavior is so complex and edge case that its not worth to fix. Writing a test to ensure something is not fixed is odd. |
Thanks, is the concern around the fix because it would break things or just that we don’t want to fix anything because it’s too much effort (relative to the benefit)? i can understand the former but the latter seems... well not really in the spirit of open source |
The problem is probably to fix only the bug without introducing regressions. You need to change the way COM objects are associated to apartments. I had commented an idea on the other thread:
There may be existing code which relies on the "wrong" apartment association for some side effect. Introducing/replacing functionality like this is always risky to get some edge case wrong. I have the impression they'd rather spend their time on creating the new COM interop system which will be more open to taking such fixes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
Hmm, now we have
|
Yeah I mentioned that above, seems its not know to be flaky, but it can't have anything to do with this PR. This is literally just cleaning up manually instead of letting the GC do it. I think it only happened once or do we have multiple failures? |
Looks like the first timer... Passed on a rebuild. |
Thank you for the fix! 🚀 |
Fixes #3305
Relates to #3271
Proposed changes
Release ITypeInfo RCW manually instead of letting the GC clean up
I'm doing this seperately from PR #3276 so it can be reviewed and merged before figuring out all the problems of the package updates.
Customer Impact
Tests should become more stable regardless how they are run
Regression?
Yes (after merging PR #3276)
Risk
no known risk
Before
Tests start failing after PR #3276
After
Tests should succeed before and after PR #3276
Test methodology
Locally running tests both with and without PR #3276
Test environment(s)
local
Microsoft Reviewers: Open in CodeFlow