Repository navigation
test(runtime): keep cancellation observers alive - #10790
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates cancellation tests to keep observer instances alive until Orleans object references are deleted, preventing flaky callback failures.
Changes:
- Adds observer lifetime safeguards during cleanup.
- Covers task and grain cancellation tests.
Show a summary per file
| File | Summary |
|---|---|
test/Orleans.Runtime.Tests/CancellationTests/GrainCancellationTokenTests.cs |
Preserves observer lifetime during cleanup. |
test/Orleans.Runtime.Tests/CancellationTests/CancellationTokenTests.cs |
Keeps task observers alive across cancellation tests. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Suppressed comments (1)
test/Orleans.Runtime.Tests/CancellationTests/CancellationTokenTests.cs:100
- This covers only
LongRunningTaskObserver, butObserverCancellationTokenTestsstill createsILongRunningObserverreferences backed by the sameWeakReference-based object manager and deletes them without a keep-alive (for example,ObserverCancellationTokenTests.cs:84-108). In the immediate/pre-cancelled paths the target can be collected before the callback, and after the last callback use cleanup can still throwReference is not associated with a local object. Apply the same end-of-scope keep-alive to those observer lifetimes as well.
GC.KeepAlive(observer);
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
Contributor
Code coverage52.14% line coverage - 52,799 / 101,267 lines Coverage details
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The .NET 10 BVT run in Azure DevOps build 3054773 failed in
MultipleGrainsTaskCancellation(delay: 300). The downloaded client log shows thatLongRunningTaskObserverwas garbage-collected before itsOnCallStartedmessages arrived. Orleans stores local observer targets through weak references, so it deregistered the reference and cleanup later threwReference is not associated with a local object.Solution
Keep each cancellation-test observer strongly reachable until after its Orleans object reference is deleted. Apply the same lifetime guarantee to every cancellation test using this observer pattern so delayed callbacks retain a valid target throughout the operation.
The full cancellation test classes pass with 112 tests, and the affected theory passes across 20 repeated runs totaling 180 test cases.
Fixes #10789
Microsoft Reviewers: Open in CodeFlow