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

Fix PeriodicTimer_ActiveOperations_TimerRooted test #68805

Merged
merged 3 commits into from
May 3, 2022

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented May 3, 2022

There are two problems with this test

  1. WaitForNextTickAsync may return a synchronously completed task, in
    which case it does not root the timer, causing our first
    WaitForTimerToBeCollected to fail because the timer was collected.
    This problem is easily reproduced by adding a small sleep after
    constructing the PeriodicTimer in Create, and I believe it is the
    cause of System.Threading.Tests.PeriodicTimerTests.PeriodicTimer_ActiveOperations_TimerRooted failing in CI #59542.
  2. There is no guarantee that the timer is not still rooted after the
    wait finishes because the returned ValueTask<bool> may be keeping
    it alive (although, it seems unlikely Roslyn will extend the lifetime across the await like this).
    Fixed by wrapping in another NoInlining method.

Fix #59542

There are two problems with this test
1. `WaitForNextTickAsync` may return a synchronously completed task, in
   which case it does not root the timer, causing our first
   `WaitForTimerToBeCollected` to fail because the timer was collected.
   This problem is easily reproduced by adding a small sleep after
   constructing the `PeriodicTimer` in `Create`, and I believe it is the
   cause of dotnet#59542.
2. There is no guarantee that the timer is not still rooted after the
   wait finishes because the returned `ValueTask<bool>` may be keeping
   it alive. This is unlikely since Roslyn should not extend the
   lifetime of the `ValueTask<bool>` like this across the await, but I
   have introduced another method just to be safe.

Fix dotnet#59542
@ghost
Copy link

ghost commented May 3, 2022

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

Issue Details

There are two problems with this test

  1. WaitForNextTickAsync may return a synchronously completed task, in
    which case it does not root the timer, causing our first
    WaitForTimerToBeCollected to fail because the timer was collected.
    This problem is easily reproduced by adding a small sleep after
    constructing the PeriodicTimer in Create, and I believe it is the
    case of System.Threading.Tests.PeriodicTimerTests.PeriodicTimer_ActiveOperations_TimerRooted failing in CI #59542.
  2. There is no guarantee that the timer is not still rooted after the
    wait finishes because the returned ValueTask<bool> may be keeping
    it alive (although, it se. Fixed by wrapping in another NoInlining method.

Fix #59542

Author: jakobbotsch
Assignees: -
Labels:

area-System.Threading

Milestone: -

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

One change, otherwise LGTM. Thanks!

…merTests.cs

Co-authored-by: Stephen Toub <stoub@microsoft.com>
@jakobbotsch jakobbotsch merged commit 6110ab2 into dotnet:main May 3, 2022
@jakobbotsch jakobbotsch deleted the fix-59542 branch May 3, 2022 17:47
@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 2022
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.

System.Threading.Tests.PeriodicTimerTests.PeriodicTimer_ActiveOperations_TimerRooted failing in CI
3 participants