From 713dbb1bbba26a72f6e7b040ce1910c215943962 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 16 Nov 2026 02:39:51 -0800 Subject: [PATCH 1/3] chore(quest): claim quest/m0/test-flakes-3/py-socket-abort.md Quest-Claim: fe48449e08fd4781 From 466f73510adc23cfe0bfe6a7a74216502e1180d7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 16 Nov 2026 02:58:41 -0800 Subject: [PATCH 2/3] fix(net): a copy reset before delivering ends its track with the reset when its closing source has no replacement A front treated an undelivered copy's end from a closing source as no verdict and kept nothing, so when nothing replaced the source the track ended Unroutable. Whether the driver saw the source closing when it read the copy's end decided the outcome, so a socket endpoint's close reached its peer as unroutable about 1 run in 6. Keep the reset as the track's loss, as a copy lost mid-serve already is. Co-Authored-By: Claude Opus 5.5 --- quest/m0/test-flakes-3/py-socket-abort.md | 32 ---------- quest/m2/sockets/remove.md | 2 - rs/moq-net/src/model/front.rs | 75 +++++++++++++++++++++-- 3 files changed, 70 insertions(+), 39 deletions(-) delete mode 100644 quest/m0/test-flakes-3/py-socket-abort.md diff --git a/quest/m0/test-flakes-3/py-socket-abort.md b/quest/m0/test-flakes-3/py-socket-abort.md deleted file mode 100644 index 8e96b579410..00000000000 --- a/quest/m0/test-flakes-3/py-socket-abort.md +++ /dev/null @@ -1,32 +0,0 @@ -# [S] A closed endpoint ends its streams as Closed, never unroutable - -## Goal - -`py/moq-rs/tests/test_socket.py::test_abort_and_endpoint_close_are_errors` -passes every run. - -## Plan - -Found 2026-11-15 by `just check` on -[moq-dev/moq#8838](https://github.com/moq-dev/moq/pull/8838), whose change does -not reach a local origin's socket. Run alone, it fails about 1 run in 3 at line -90: after `a.close()`, `server.consumer.read_frame()` raises -`moq.Error.Protocol: unroutable` instead of `moq.Error.Closed`, so closing an -endpoint races its route's withdrawal against its streams' ending. Fix the -endpoint at the cause, as the epic's rules ask. - -First check whether it still reproduces after -[moq-dev/moq#8825](https://github.com/moq-dev/moq/pull/8825), which makes every -ending of a socket endpoint run its cleanup and likely fixes it: run the test -alone in a loop on a base that includes it. If it no longer fails, delete this -quest; if it does, the cause lies elsewhere. - -Decided 2026-11-16 (maintainer, /quest-plan of the pre-cut audit): socket -endpoints leave moq for Kixel, and -[their removal](/quest/m2/sockets/remove.md) deletes this test with the -Python wrapper. So do not fix the endpoint here. If the test still flakes -before the removal lands, skip it with the removal quest as its owner and -delete this quest; the removal deletes this quest otherwise. Kixel's port -inherits the race, which goes in that PR's follow-ups for Kixel's tree. - -Public API: none. Wire: none. diff --git a/quest/m2/sockets/remove.md b/quest/m2/sockets/remove.md index a078b6f91c6..19b8489c707 100644 --- a/quest/m2/sockets/remove.md +++ b/quest/m2/sockets/remove.md @@ -78,8 +78,6 @@ For the PR: must already be off it. - Record the PR's parent commit in the PR body: it is the reference Kixel ports from. -- If [the closed-endpoint flake](/quest/m0/test-flakes-3/py-socket-abort.md) - is still open, delete it here: its test leaves. - Run `just test interop --all` (moq-ffi changes) and `just api-diff`. Public API: breaking for `main`-only API in every language; nothing on diff --git a/rs/moq-net/src/model/front.rs b/rs/moq-net/src/model/front.rs index 122db890cc5..344f2bea598 100644 --- a/rs/moq-net/src/model/front.rs +++ b/rs/moq-net/src/model/front.rs @@ -185,8 +185,9 @@ struct Track { /// The most recent refusal, reported when every source has refused, with the Retry /// Interval an upstream refusal asked for. refusal: Option<(Error, Option)>, - /// Why the serving copy died mid-serve, while its re-splice is asked for. A refusal of - /// that re-splice reports this instead: the source closing is what ended the track. + /// Why the serving copy died mid-serve, or before delivering from a closing source, while + /// a re-splice is awaited. A refusal of that re-splice, or the front ending first, + /// reports this instead: the source closing is what ended the track. lost: Option, /// Whether anyone reads the track: a copy is only spliced in for a reader. wanted: bool, @@ -276,8 +277,8 @@ impl Front { self.serving.map(|(source, _)| source) } - /// Why `track`'s serving copy died mid-serve, while its re-splice is still asked for. - /// A track the front ends meanwhile ends with this rather than the front's end. + /// Why `track`'s serving copy died, while its re-splice is still awaited. A track the + /// front ends meanwhile ends with this rather than the front's end. pub(super) fn lost(&self, track: &str) -> Option { self.tracks.get(track)?.lost.clone() } @@ -625,8 +626,14 @@ impl Front { retry: None, }); } + // Died before producing anything from a source on its way out: not a refusal, but + // what ended the track unless a replacement serves it. + Err(err) if closing => { + track.state = TrackState::Idle; + track.lost = Some(err); + } // Died before producing anything: a refusal. - Err(err) => self.refuse(name, source, closing, (err, None), actions), + Err(err) => self.refuse(name, source, false, (err, None), actions), } } @@ -1258,6 +1265,64 @@ mod tests { ); } + /// A copy reset before delivering, seen only once its source began closing, such as a + /// session of a closing socket endpoint, is no refusal, yet ends the track with the reset + /// rather than `Unroutable` when nothing replaces the source, or when its replacement + /// refuses. + #[test] + fn an_undelivered_copy_of_a_closing_source_reports_the_loss() { + let reset = || Error::from(crate::StreamError::Session(crate::SessionError::Cancel)); + let mut front = serving(local(1), 100); + assert_actions( + front.step(Event::TrackEnded { + track: name("video"), + source: 100, + closing: true, + result: Err(reset()), + delivered: false, + }), + &[], + ); + assert!(front.tracks[&name("video")].refused.is_empty()); + front.step(Event::SourceClosed { source: 100 }); + + let mut replaced = front.clone(); + replaced.step(Event::Selected { + best: Some(local(2)), + serving_closing: false, + }); + replaced.step(Event::Resolved { + route: 2, + result: Ok(200), + }); + assert_actions( + replaced.step(Event::TrackInfo { + track: name("video"), + source: 200, + closing: false, + result: Err(Error::NotFound), + retry: None, + }), + &[Action::Abort { + track: name("video"), + err: reset(), + retry: None, + }], + ); + + assert_actions( + front.step(Event::Selected { + best: None, + serving_closing: false, + }), + &[Action::End { err: Error::Unroutable }], + ); + assert_eq!( + front.lost("video").map(|err| err.to_string()), + Some(reset().to_string()) + ); + } + /// A source that loses a copy mid-serve and then refuses its re-splice, such as a /// closing socket endpoint, ends the track with the loss, not the refusal. #[test] From 8646071c379d6e8842a381bce266e445e151aca7 Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Mon, 16 Nov 2026 03:28:47 -0800 Subject: [PATCH 3/3] fix(net): a closing source's answer to a query is kept as the loss too The driver reports a copy reset before its metadata was read as the query's answer, not the copy's end, so the same race reached refuse's closing branch. Keep every closing source's answer as the track's loss there, unless an earlier loss stands. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/front.rs | 121 ++++++++++++++++++---------------- 1 file changed, 66 insertions(+), 55 deletions(-) diff --git a/rs/moq-net/src/model/front.rs b/rs/moq-net/src/model/front.rs index 344f2bea598..a8e729d74a3 100644 --- a/rs/moq-net/src/model/front.rs +++ b/rs/moq-net/src/model/front.rs @@ -185,9 +185,9 @@ struct Track { /// The most recent refusal, reported when every source has refused, with the Retry /// Interval an upstream refusal asked for. refusal: Option<(Error, Option)>, - /// Why the serving copy died mid-serve, or before delivering from a closing source, while - /// a re-splice is awaited. A refusal of that re-splice, or the front ending first, - /// reports this instead: the source closing is what ended the track. + /// Why the serving copy died mid-serve, or what a closing source answered, while a + /// re-splice is awaited. A refusal of that re-splice, or the front ending first, reports + /// this instead: the source closing is what ended the track. lost: Option, /// Whether anyone reads the track: a copy is only spliced in for a reader. wanted: bool, @@ -626,14 +626,8 @@ impl Front { retry: None, }); } - // Died before producing anything from a source on its way out: not a refusal, but - // what ended the track unless a replacement serves it. - Err(err) if closing => { - track.state = TrackState::Idle; - track.lost = Some(err); - } // Died before producing anything: a refusal. - Err(err) => self.refuse(name, source, false, (err, None), actions), + Err(err) => self.refuse(name, source, closing, (err, None), actions), } } @@ -651,9 +645,11 @@ impl Front { let serving = self.serving.is_some_and(|(serving, _)| serving == source); let track = self.tracks.get_mut(&name).expect("refusing a known track"); track.state = TrackState::Idle; - // A closing source's answer is not a verdict: it is on its way out and - // its replacement is asked afresh. + // A closing source's answer is not a verdict: it is on its way out and its + // replacement is asked afresh. It is still what ended the track if nothing replaces + // the source, unless an earlier loss did. if closing { + track.lost.get_or_insert(refusal.0); return; } // A route that lost the content says nothing of the track: wait for another of its @@ -1268,59 +1264,74 @@ mod tests { /// A copy reset before delivering, seen only once its source began closing, such as a /// session of a closing socket endpoint, is no refusal, yet ends the track with the reset /// rather than `Unroutable` when nothing replaces the source, or when its replacement - /// refuses. + /// refuses. The driver reports it as the copy's end once spliced, or as the answer to + /// its query when the reset came before the metadata was read. #[test] - fn an_undelivered_copy_of_a_closing_source_reports_the_loss() { + fn a_closing_source_reset_reports_the_loss() { let reset = || Error::from(crate::StreamError::Session(crate::SessionError::Cancel)); - let mut front = serving(local(1), 100); - assert_actions( - front.step(Event::TrackEnded { + let ended = || { + let mut front = serving(local(1), 100); + let actions = front.step(Event::TrackEnded { track: name("video"), source: 100, closing: true, result: Err(reset()), delivered: false, - }), - &[], - ); - assert!(front.tracks[&name("video")].refused.is_empty()); - front.step(Event::SourceClosed { source: 100 }); - - let mut replaced = front.clone(); - replaced.step(Event::Selected { - best: Some(local(2)), - serving_closing: false, - }); - replaced.step(Event::Resolved { - route: 2, - result: Ok(200), - }); - assert_actions( - replaced.step(Event::TrackInfo { - track: name("video"), - source: 200, - closing: false, - result: Err(Error::NotFound), - retry: None, - }), - &[Action::Abort { + }); + (front, actions) + }; + let answered = || { + let mut front = querying(local(1), 100); + let actions = front.step(Event::TrackInfo { track: name("video"), - err: reset(), + source: 100, + closing: true, + result: Err(reset()), retry: None, - }], - ); - - assert_actions( - front.step(Event::Selected { - best: None, + }); + (front, actions) + }; + for (mut front, actions) in [ended(), answered()] { + assert_actions(actions, &[]); + assert!(front.tracks[&name("video")].refused.is_empty()); + front.step(Event::SourceClosed { source: 100 }); + + let mut replaced = front.clone(); + replaced.step(Event::Selected { + best: Some(local(2)), serving_closing: false, - }), - &[Action::End { err: Error::Unroutable }], - ); - assert_eq!( - front.lost("video").map(|err| err.to_string()), - Some(reset().to_string()) - ); + }); + replaced.step(Event::Resolved { + route: 2, + result: Ok(200), + }); + assert_actions( + replaced.step(Event::TrackInfo { + track: name("video"), + source: 200, + closing: false, + result: Err(Error::NotFound), + retry: None, + }), + &[Action::Abort { + track: name("video"), + err: reset(), + retry: None, + }], + ); + + assert_actions( + front.step(Event::Selected { + best: None, + serving_closing: false, + }), + &[Action::End { err: Error::Unroutable }], + ); + assert_eq!( + front.lost("video").map(|err| err.to_string()), + Some(reset().to_string()) + ); + } } /// A source that loses a copy mid-serve and then refuses its re-splice, such as a