GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||
GeezerVison is showing github.com — fix(test): keep observer cancellation targets alive by ReubenBond · Pull Request #10897 · dotnet/orleans Conversation
|
| Severity | Finding |
|---|---|
test/Orleans.Runtime.Tests/CancellationTests/ObserverCancellationTokenTests.cs — GC.KeepAlive(observer) is currently only executed after the cancellation assertion and cleanup.… |
This PR targets flakiness in ObserverCancellationTokenTests caused by Orleans holding observer targets via weak references, allowing the observer implementation to be garbage-collected too early (especially on immediate-cancellation paths), which can prevent cancellation from reaching the observer and make the test pass unexpectedly.
Changes:
GC.KeepAlive(...) calls to keep observer implementations strongly reachable through subscription, cancellation, unsubscribe, and object reference cleanup.| File | Description |
|---|---|
| test/Orleans.Runtime.Tests/CancellationTests/ObserverCancellationTokenTests.cs | Adds GC.KeepAlive calls intended to prevent observer target GC during cancellation test execution. |
test/Orleans.Runtime.Tests/CancellationTests/ObserverCancellationTokenTests.cs:251
cancelImmediately path, the observers are not otherwise used before the cancellation assertions. If Assert.ThrowsAnyAsync fails and throws, the current cleanup block (including GC.KeepAlive) is skipped, which undermines the lifetime guarantee this test relies on. Consider moving the unsubscribe/delete/KeepAlive logic into a finally so it runs regardless of assertion outcome and forces the observer targets to remain live through the awaited operations. foreach (var g in grains)
{
fixture.GrainFactory.DeleteObjectReference<ILongRunningObserver>(g.Reference);
GC.KeepAlive(g.Observer);
}
test/Orleans.Runtime.Tests/CancellationTests/ObserverCancellationTokenTests.cs:330
ObserverTaskCancellation, placing GC.KeepAlive(observer) after Assert.ThrowsAnyAsync means it will never run when the assertion fails (the exact flaky mode this change is trying to prevent), so the observer can still be collected early in the immediate-cancellation path. Wrap the assertion+optional wait in a try and move cleanup + KeepAlive into a finally to guarantee execution. await grain.Unsubscribe(reference);
fixture.GrainFactory.DeleteObjectReference<ILongRunningObserver>(reference);
GC.KeepAlive(observer);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Review tier: Lite
Findings: None
| Severity | Finding |
|---|---|
test/Orleans.Runtime.Tests/CancellationTests/ObserverCancellationTokenTests.cs — GC.KeepAlive(observer) is currently only executed after the cancellation assertion and cleanup.… View resolved comment |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Flaky InterleavingObserverTaskCancellation on macOS net8.0
There was an error while loading. Please reload this page.