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

Disable tests with WaitForPendingFinalizers in gcstress testing #104102

Conversation

janvorli
Copy link
Member

Some if not all tests from the Methodical suite that use GC.WaitForPendingFinalizers timeout due to the fact that a finalizer of Gen2GcCallback calls a callback that ends up creating another finalizable object that is ready to be finalized. Also a GC memory is allocated in that callback, which triggers the GC stress collection. So the finalization thread keeps finalizing objects on the queue forever and the GC.WaitForPendingFinalizers never exits.

This change disables all tests in the Methodical suite that wait for pending finalizers when running with GC stress enabled.

Closes #104062

Some if not all tests from the Methodical suite that use GC.WaitForPendingFinalizers
timeout due to the fact that a finalizer of Gen2GcCallback calls a callback that
ends up creating another finalizable object that is ready to be finalized. Also
a GC memory is allocated in that callback, which triggers the GC stress collection.
So the finalization thread keeps finalizing objects on the queue forever and the
GC.WaitForPendingFinalizers never exits.

This change disables all tests in the Methodical suite that wait for pending
finalizers when running with GC stress enabled.
@janvorli janvorli added this to the 9.0.0 milestone Jun 27, 2024
@janvorli janvorli self-assigned this Jun 27, 2024
Copy link
Contributor

Tagging subscribers to this area: @dotnet/gc
See info in area-owners.md if you want to be subscribed.

@janvorli
Copy link
Member Author

/azp run runtime-coreclr gcstress0x3-gcstress0xc

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jkotas
Copy link
Member

jkotas commented Jun 27, 2024

Would @VSadov change #103738 be a better fix for this problem?

Trying to find every test that calls WaitForPendingFinalizers somewhere gets boring fast.

@jkotas jkotas requested a review from VSadov June 27, 2024 20:32
@VSadov
Copy link
Member

VSadov commented Jun 27, 2024

I think #103738 is a better fix. Perhaps we should review and merge it.

I wanted to get it stress-green, at least on runtime stress, but we keep seeing stress issues not related to the PR.
The PR itself could be useful to deal with those as it makes things more robust and faster.

I also wanted to be able to run Libraries tests and that is mostly possible, but just like with runtime tests there are few tests that are sensitive to GC stress in some subtle ways (i.e. anything that checks for "reasonable" time spent for something...) and there are some tests (i.e. Dynamic stuff, RegularExpressions,..) that take ridiculously long even with more optimized stress approach.

The change allows to run many Libraries tests and thus is very useful for local investigations, but for lab runs we may need to come up with some filtering/excluding mechanism.

@cshung
Copy link
Member

cshung commented Jun 27, 2024

I am wondering if we could provide a better API for this purpose, something like GC.WaitForCollection(weak reference to obj) or GC.OnCollection(weak reference to object, Action callback);?

Other than preventing the infinitely locked situation under GCStress, this API will also:

  • Make the intent of the tests clear (i.e. what exactly are we waiting for)
  • Potentially allow a faster response time (e.g. WeakRef might get null out early after background mark, and there is no need to wait until all finalizer completes), and
  • Hopefully reduce the need for using finalizers, you can still use GC to manage life time, but not unnecessarily lengthening object lifetime through finalizer.

It is just a rough idea, I don't know how feasible that would be yet.

@jkotas
Copy link
Member

jkotas commented Jun 27, 2024

I am wondering if we could provide a better API for this purpose, something like GC.WaitForCollection(weak reference to obj) or GC.OnCollection(weak reference to object, Action callback);?

This looks very much like phantom references (that can be used as finalizer replacement among other things). If we wanted to expose them, I expect that it would be a new type of GC handle at the lowest level.

@janvorli
Copy link
Member Author

I am fine fixing the problem itself instead of disabling tests like this. I just made it as a quick way to make the gcstress legs green again.

@janvorli
Copy link
Member Author

janvorli commented Jul 8, 2024

Closing this PR as #103738 has implemented a fix for the issue.

@janvorli janvorli closed this Jul 8, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 9, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime-coreclr gcstress0x3-gcstress0xc has been failing for the past month
4 participants