Skip to content

fix(moq-net): an origin with a closed lite-07 session's orphan tears down and frees its route node - #9106

Open
kixelated wants to merge 1 commit into
mainfrom
fix/origin-orphan-cycle
Open

kixelated wants to merge 1 commit into
mainfrom
fix/origin-orphan-cycle

Conversation

@kixelated

@kixelated kixelated commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

Nightly Fuzz (session_lite) (run 44342367698) exits 77: LeakSanitizer reports about 33 KB of indirect leaks on the very first corpus input ([0], a lite-07 session with an empty script). Every lite-07 session run leaks.

Since moq-dev/moq#8987, a lite-07 session that closes leaves each claim it served in the origin's route node as an orphan (routed::Left, which holds an origin::Claim). That makes two problems:

  1. A reference cycle. The origin's shared state holds the route node (OriginState::route_node), the node holds the orphan, and the orphan's claim holds the origin's shared state again. Nothing breaks that cycle, not even teardown, so the whole origin (table, broadcasts, sessions' route state) leaks.
  2. The origin never finishes. A claim holds a Keepalive on the origin's driver, so an orphan keeps the driver running after every Producer handle and session is gone. The orphan only goes away when another session serves the claim or the node's reader lets it go, and that reader runs inside the same driver, so it never does.

Approach

  • Orphaning a claim disowns it (Claim::disown drops its keepalive). What a closed session left behind is not an owner, like the other read handles: it keeps the claim shown while the origin lives, and goes away with the origin.
  • The origin's teardown takes the route node out of its shared state and drops it outside the lock, which breaks the cycle. A route_node() call after teardown no longer stores a fresh node.
  • The source_errors integration fixture now holds its relay origin, as a real relay does. It had relied on the dead upstream's orphan to keep an origin with no owner alive.
  • The drill mutation relay-withdraws-lost-publisher is retargeted at the new line. It still breaks its drill.

Validation

  • Reproduced with cargo fuzz run session_lite on the logged input ([0]): the same LeakSanitizer report, 93 allocations. After symbolizing it, the leaked roots were route::node::Node::new from Consumer::route_node and the origin's Producer::new. With the fix, the input runs clean.
  • A 3-minute cargo fuzz run session_lite from the generated seeds: 10k runs, no leak or failure.
  • New a_torn_down_origin_lets_go_of_what_closed_sessions_left: a session serves a claim and closes, then the origin's handles drop, and the test asserts the route node is freed. It fails if either half of the fix is removed, each checked separately.
  • just rs test -p moq-net --all-features: 3905 passed. just check passes, including the drill sensitivity check.
  • No input was committed under fuzz/regressions/session_lite: the input is [0], which the seeds already cover, and the stable replay runs without LeakSanitizer. The unit test holds the regression instead.

Caused by

  • moq-dev/moq#8987 - added route-node orphans that hold an origin claim (and its driver keepalive) inside a node the origin holds, so a closed lite-07 session's claims keep the origin alive and leak it (found by check: nightly fuzz)

Impact

  • Behavior: an origin whose last Producer and Route handles have dropped now finishes and tears down once its live sessions end, even when a closed lite-07 session left claims behind. Before, those orphans kept it running forever. No public API or wire change.

Alternatives

  • Hold the node weakly in the origin: the node would die with the last session, which releases its orphans at once and defeats them (a reconnecting peer's claims would go offline).
  • Break only the cycle at teardown: the driver never reaches teardown while an orphan holds its keepalive, so only an external drop of the driver (as the fuzz harness does) would free it.

Waiting

  • Should an orphaned claim keep an otherwise unowned origin alive? This PR says no: orphans are shown state, not owners, matching "read handles are not owners" in origin::Driver's docs. A relay always holds its origin, so its behavior is unchanged. Recommendation: keep this.

Models

Size: S
Implementer: Claude Code, claude-opus-5-5, unknown effort

(Written by Opus 5.5)

🤖 Generated with Claude Code

Review

Rewritten by quest review after each round.

  • Head: 839c215

  • Base: origin/main at 6f420bf

  • Risk: medium, the base has no RISK.md to name what is always high or customer-facing, so every change is medium

  • Classified: medium by default

  • Reviewer: Codex, gpt-6.1-sol, medium effort

  • Session: 01a1f04b-00e9-7132-b255-04a0340d7c23, round 1

  • Score: 9/10, The ownership changes address the reference cycle coherently and include regression coverage; no actionable regressions were found, but builds and tests were not run as instructed.

  • Rounds: 1; first round 0; findings 0: fixed 0, refuted 0, open 0

  • Findings: none

…down and frees its route node

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated
kixelated marked this pull request as ready for review November 18, 2026 20:14

@pullfrog pullfrog Bot 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.

✅ No new issues found.

Approach: Sound. The fix handles both causes of the leak. Disowning the orphan's Keepalive lets the driver reach teardown, and teardown then breaks the OriginState::route_node → orphan → RouteState → origin-state cycle. This keeps orphans visible while the origin lives and doesn't weaken the node, which would have defeated reconnects.

Reviewed changes

The full diff of the single commit, checked against origin.rs, route/node.rs and lite/subscriber/routed.rs.

  • Claim::disown: RouteState's keepalive becomes a Mutex<Option<Keepalive>> that Routed::orphan clears before leaving Left in the node.
    • Forwarded claims carry publisher: None, so this removes all of the orphan's ownership.
    • A reconnecting session serves a fresh Claim and the disowned orphan is released, so a live claim is never disowned.
  • Teardown frees the node: DriverState::teardown takes shared.route_node under the lock and drops it outside.
    • RouteState::drop → retract needs the shared lock, so dropping outside it avoids a deadlock.
    • TaskSet::owned() replaces the old set before this point, which cancels FeedOwnClaims and RouteTimer and drops their node clones.
  • No node after close: create_route_node stops storing a node once closed is set. Tasks::push already refuses work after close, so a late route_node() call leaves nothing behind.
  • Tests and fixtures:
    • New a_torn_down_origin_lets_go_of_what_closed_sessions_left, using a test-only WeakNode.
    • The source_errors fixture now holds its relay origin.
    • The drill patch context is updated for the new disown() line.

Pullfrog  | View workflow run | Using claude-opus-5-5 | 𝕏

@coderabbitai

coderabbitai Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Route claims now store keepalives in optional mutex-protected state, which Claim::disown can take and drop. Routed orphan handling disowns the served route’s dynamic handle before stream orphan handling. Origin teardown takes the route node from shared state and drops it after releasing the lock. A test checks that the node is released after the subscriber and consumer are dropped and the origin driver tears down.

Merge Risk: Minimal · up to 839c2

This change lets an origin tear down after its lite-07 sessions close, even when those sessions leave orphaned claims behind. No merge-blocking risk is evident, and the new test covers the leak.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the main change: an origin with a closed lite-07 session's orphan now tears down and frees its route node. It matches the raw summary, which covers disowning orphaned claims and taking…
Description check Passed The description explains the problem (a reference cycle and an origin that never finishes after a lite-07 session closes), the approach (disowning claims, breaking the cycle at teardown, updating the …
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 main change: an origin with a closed lite-07 session's orphan now tears down and frees its route node. It matches the raw summary, which covers disowning orphaned claims and taking the route node out of shared state at teardown. The title is long (98 characters) but specific and accurate.

Full details: Description check

Explanation

The description explains the problem (a reference cycle and an origin that never finishes after a lite-07 session closes), the approach (disowning claims, breaking the cycle at teardown, updating the source_errors fixture, retargeting the drill mutation), validation, and alternatives. It matches the changed files in the raw summary.

Finishing Touches

Simplify code

  • 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

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: 11905b12-7bc6-48de-8dcd-15c552669b60
Commits

Reviewing files that changed from the base of the PR and between 6f420bf and 839c215.

Files selected for processing: 6

  • rs/moq-net/src/lite/subscriber/routed.rs
  • rs/moq-net/src/lite/subscriber/routed/tests.rs
  • rs/moq-net/src/model/origin.rs
  • rs/moq-net/src/route/node.rs
  • rs/moq-net/tests/integration/source_errors.rs
  • test/drill/mutations/relay-withdraws-lost-publisher.patch

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

This branch has not been deployed

No deployments
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