net: a replaced copy let go with its track open loses a group it gave up under the resume point

Open
#10,340 2 comments 1 reaction 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
rust

Research direction

Start with rs/moq-net/src/model/resume.rs and reproduce the failure using the supplied test in mod test, checking why asked_for(&b, 2) is false. Then read Reader::owed and how it handles replaced copies and runs they can still deliver. Done means the fill for group 2 is retained and the supplied scenario passes without breaking the three named regression tests.

Written by the indexing model from the issue text.

Description

quest

A logical reader can lose a group under the serving copy's resume point after a route switch, when a replaced copy gives that group up and is then let go while its track stays open.

Scenario

  1. Route A's copy holds groups 0, 1 and 4. The reader reads them, then the front switches to route B, whose live feed starts at 4 (so 2 and 3 can come from B only as fills).
  2. A drops group 2, while group 3 may still land on it. Reader::owed subtracts A's whole fed span (copy.replaced && !copy.fills && copy.feeds), so no fill is kept for 2 either.
  3. A then skips group 3 while its track stays open. Nothing is left to land on A, so Copy::retains returns No and let_go drops it.
  4. ran_short re-arms the serving route's walk only when poll_first sees the copy end cleanly (done = Some(Ok)), which never happens here. gave_up covers only drains. Nothing asks B for group 2, and an ordered read waits at it.

This affects bounded and unbounded reads alike. On main it predates moq-dev/moq#10176, which only widened owed and ran_short to unbounded reads.

Reproduction

Add this to rs/moq-net/src/model/resume.rs's mod test. It fails at asked_for(&b, 2):

	/// A replaced copy let go while its track stays open, after giving up one group the reader
	/// lacks and having the rest it still fed skipped, leaves that group to the serving route:
	/// no fill was kept for what it still fed.
	#[test]
	fn a_replaced_copy_let_go_open_has_a_group_it_gave_up_asked_again() {
		let routes = Producer::new();
		let logical = logical(&routes);
		let a = received_copy();
		routes.serve(a.consume());
		let mut sub = subscribe_until(&logical, 6);
		for key in [0, 1, 4] {
			write(&a, key);
		}
		let mut got = drain(&mut sub, false);
		got.sort_unstable();
		assert_eq!(got, [0, 1, 4]);
		let mut b = received_copy();
		routes.serve(b.consume());
		// Its live feed starts at the resume point, so 2 comes only as a fill.
		b.start_at(4).unwrap();
		write(&b, 5);
		assert_eq!(drain(&mut sub, false), [5]);
		// The old route gives 2 up while 3 may still land on it.
		a.drop_groups(2..3);
		assert!(sub.poll_recv_group(&fresh()).is_pending());
		// Then it skips 3, its track still open, so nothing is left to land on it.
		a.skip_groups(3..4);
		assert!(sub.poll_recv_group(&fresh()).is_pending());
		assert!(sub.poll_recv_group(&fresh()).is_pending());
		assert!(asked_for(&b, 2), "{:?}", b.subscription());
		write(&b, 2);
		assert_eq!(drain(&mut sub, false), [2]);
	}

What a fix has to keep

The obvious fix re-arms Resumed::Route whenever let_go drops a copy that still fed a group the reader lacks under the resume point. That over-asks: it breaks a_kept_out_key_above_a_finished_backfill_is_asked_from_itself (a copy let go past the budget gets asked again), and even limited to copies within their budget it breaks an_unplaced_time_start_waits_on_a_replaced_copy and ..._only_to_its_end (the serving route gets asked for history those tests leave unasked). The reviewer's suggestion is narrower: in Reader::owed, subtract only the runs the replaced copy can still deliver (not its drops), so the fill for group 2 is kept.

Found by Codex review on moq-dev/moq#10176.

(Written by Claude Opus 5.5)

Dominant language
Rust
Stars
1.6k
Forks
251
Avg merge
10h 10m
Merged PRs (30d)
822

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from moq-dev/moq

All issues in moq-dev/moq

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.