Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

test: fix flaky owner-collection check in ExternalObjectOwnershipTests - #7794

Merged
thomhurst merged 1 commit into
mainfrom
fix/flaky-external-ownership-test
Nov 16, 2026
Merged

thomhurst merged 1 commit into
mainfrom
fix/flaky-external-ownership-test

Conversation

@thomhurst

@thomhurst thomhurst commented Nov 16, 2026 •

Copy link
Copy Markdown
Owner

Concurrent_Capture_Registration_And_Counter_Release_Preserve_Owner_Lifetime flakes under load: "The owner is retained by the ownership registry".

Repro: 16 copies of TUnit.UnitTests running ExternalObjectOwnershipTests at once fails about once in 60 runs. One run alone never fails.

On failure the owner had no counted pins and nothing was tracked. A full dump taken at that point showed both ScopeOwner instances with 0 GC roots. So the owner was only reachable for a moment, most likely from a worker thread still unwinding a Debug-build async frame. It wasn't leaked.

Fix: CollectOwner retries the GC for up to ~1s before failing. A real leak still fails; I checked by pinning the owner in a static field.

Results: 0 failures in 800 stressed runs (it was about 1 in 60 before). TUnit.UnitTests passes on net10 and net11.

Summary by CodeRabbit

  • Tests
    • Ownership-related checks now allow repeated collection attempts and brief waits before reporting that an owner remains reachable. This reduces sensitivity to garbage collection timing while preserving detection of owners that continue to be retained. The change affects automated test behavior only; it does not alter application functionality or what users see.

The concurrent ownership test checked the owner's weak reference after a single
GC. A worker thread that just completed can still hold the owner in a frame it
is unwinding, so under load the check failed about once in 60 runs. A heap dump
of a failure showed the owner with no GC roots. Retry the collection for up to
a second; a real leak still fails.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T20:53:57.087706Z 31dee3a PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The ownership tests now await an asynchronous helper. The helper retries garbage collection, finalizer processing, and owner reachability checks up to 50 times, with a 20 ms delay between attempts. It throws the existing registry-retention error if the owner remains reachable.

Changes: Ownership Collection Tests

Layer / File(s) Summary
Async owner collection checks
tests/TUnit.UnitTests/ExternalObjectOwnershipTests.cs
The helper retries owner collection and reachability checks, waiting 20 ms between attempts. Four ownership tests now await the helper.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Other

Possibly related PRs

Merge Risk: Minimal · up to 31dee

This change only makes an intermittently failing unit test more reliable and does not affect product behavior. It is low risk to merge.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the actual change: a fix to a flaky owner-collection check in ExternalObjectOwnershipTests. The summary confirms the test now retries collection and waits for the owner to become unrea…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the actual change: a fix to a flaky owner-collection check in ExternalObjectOwnershipTests. The summary confirms the test now retries collection and waits for the owner to become unreachable, which matches the title. The 'test:' prefix correctly marks it as a test-only change. The title is short, specific, and in the imperative style.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A rabbit waits as owners fade,
Through fifty rounds the checks are made.
The finalizers run their course,
A brief pause follows each attempt, of course.
If reachability stays in sight,
The test reports the registry’s hold tonight.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d00f87e3-11c4-4049-a554-391aaf0db84e
Commits

Reviewing files that changed from the base of the PR and between 19db9d7 and 31dee3a.

Files selected for processing: 1

  • tests/TUnit.UnitTests/ExternalObjectOwnershipTests.cs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

@github-actions

Copy link
Copy Markdown
Contributor

Review: LGTM. The retry loop in CollectOwnerAsync (up to 50 × GC + 20ms delay) addresses the transient-root flake. A real leak still fails after ~1s, and IsOwnerAlive is already NoInlining, so the check doesn't keep the target alive itself. The call sites are correctly updated to await.

Two small optional notes:

  • Keep the retry bound as a named constant if it's reused elsewhere.
  • The await Task.Yield() before the first call site is now redundant, since the helper awaits anyway.

Nothing blocking.

@greptile-apps

greptile-apps Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Low impact] The PR appears safe to merge; no actionable issues were found.

Summary

The PR reduces flaky owner-collection checks without changing application code.

  • Owner-collection tests retry before reporting that an owner is still reachable.

Reviews (2) · Last reviewed commit: "test: retry owner collection in External..." · Reviewed by Greptile

@thomhurst
thomhurst merged commit d505566 into main Nov 16, 2026
27 checks passed
@thomhurst
thomhurst deleted the fix/flaky-external-ownership-test branch November 16, 2026 21:18
This was referenced Nov 16, 2026

This branch was previously deployed

1 inactive deployment
Pull Requests — 31dee3a3 Deployed Nov 16, 2026 by thomhurst via modularpipeline (ubuntu-latest) #21732
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant