Skip to content

test(runtime): keep cancellation observers alive - #10790

Merged
ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-daily-ci-health-pass-105
Aug 23, 2026
Merged

ReubenBond merged 1 commit into
dotnet:mainfrom
ReubenBond:rb-daily-ci-health-pass-105

Conversation

@ReubenBond

@ReubenBond ReubenBond commented Aug 23, 2026 •

Copy link
Copy Markdown
Member

Problem

The .NET 10 BVT run in Azure DevOps build 3054773 failed in MultipleGrainsTaskCancellation(delay: 300). The downloaded client log shows that LongRunningTaskObserver was garbage-collected before its OnCallStarted messages arrived. Orleans stores local observer targets through weak references, so it deregistered the reference and cleanup later threw Reference 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

Copilot AI lite review requested due to automatic review settings August 23, 2026 05:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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, but ObserverCancellationTokenTests still creates ILongRunningObserver references backed by the same WeakReference-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 throw Reference 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

@github-actions

Copy link
Copy Markdown
Contributor

Code coverage

52.14% line coverage - 52,799 / 101,267 lines

Coverage details

@ReubenBond
ReubenBond merged commit 24b0259 into dotnet:main Aug 23, 2026
76 checks passed
@ReubenBond
ReubenBond deleted the rb-daily-ci-health-pass-105 branch August 23, 2026 05:59
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 22, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky test: cancellation observer can be collected before start notifications

2 participants