From 25faf8b80e259e24c990f8f5691b95904e7d0cfe Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Tue, 17 Nov 2026 17:37:44 -0800 Subject: [PATCH 1/2] fix(moq-net): a drop poll's change reopens the ordered read gates An ordered reader drop-polls its source on every read since #8910, and on a resumed subscription that poll reaches the serving cursor's `poll_drop`. That poll syncs the window and probes fills on its own waiter: it can move the window, ask a fill, or hear a fill's answer, all of which change what the cursor's group read walks. Nothing reopened the read gate, and a disarm would not have helped: the resume and ordered gates parked on the cursor's gate and answer `Pending` again until a wake reaches them, which a silent disarm never sends. The reader parks for good on a group that is already servable. `Idle::reopen` disarms and wakes through the gate's own waiter, so every gate the read nests in reads again. `Cursor::poll_drop` reopens the read gate when the window revision or the fill view it walks changed. Plain `disarm` stays silent for the hot paths that disarm inside or alongside the read. Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/model/idle.rs | 4 ++- rs/moq-net/src/model/track.rs | 17 ++++++++++++ rs/moq-net/src/util/idle.rs | 49 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+), 1 deletion(-) diff --git a/rs/moq-net/src/model/idle.rs b/rs/moq-net/src/model/idle.rs index b3d008ea6c8..8ad171a3425 100644 --- a/rs/moq-net/src/model/idle.rs +++ b/rs/moq-net/src/model/idle.rs @@ -12,7 +12,9 @@ //! //! Gates nest: a read through a gate that polls another gated reader passes it the outer //! gate's waiter, whose waker stays the same across reads, so the inner gate keeps its arm -//! and its wake reaches the outer gate on the way to the task. +//! and its wake reaches the outer gate on the way to the task. A change made outside the +//! read, such as a drop poll hearing a fill's answer, reopens the gate instead of disarming +//! it, so that wake reaches the outer gates too. pub(super) use crate::util::Idle; diff --git a/rs/moq-net/src/model/track.rs b/rs/moq-net/src/model/track.rs index 4a8f327b4cb..b769a437450 100644 --- a/rs/moq-net/src/model/track.rs +++ b/rs/moq-net/src/model/track.rs @@ -8434,6 +8434,8 @@ impl Cursor { /// The next run given up, judging the live edge first only when `probe`. #[cfg_attr(not(feature = "async"), allow(dead_code, reason = "async-only"))] fn poll_drop(&mut self, probe: bool, waiter: &kio::Waiter) -> Poll<(ops::Range, Hole)> { + // What the group read walks, which this poll may move outside that read. + let walks = (self.filter.revision, self.fill_view()); self.sync(); if self.drops.is_none() { self.drops = Some(Box::new(DropCursor::new(&self.state.read()))); @@ -8453,6 +8455,12 @@ impl Cursor { self.probe(from, &drift, waiter); judged = Some(drift); } + // The window settled, or a fill was asked or answered, on this poll's waiter rather + // than the one the group read parked on: that read, and every gate it nests in, reads + // again. + if (self.filter.revision, self.fill_view()) != walks { + idle::Idle::reopen(&mut self.idle); + } // A cap at or below the floor leaves nothing to report, not a reversed span. let floor = self.floor(); let within = Within { @@ -9205,6 +9213,15 @@ impl Cursor { group } + /// What a group read consults of the fills: the lowest group still owed, whether a filled + /// one waits to be taken, and whether any is owed at all. + fn fill_view(&self) -> (Option, bool, bool) { + let Some(misses) = &self.misses else { + return (None, false, false); + }; + (misses.lowest_wanted(), misses.has_filled(), misses.is_waiting()) + } + /// Whether a fill still owes this cursor a group, so the end of the feed is not its end. fn awaits_fill(&self) -> bool { self.misses.as_ref().is_some_and(|misses| misses.is_waiting()) diff --git a/rs/moq-net/src/util/idle.rs b/rs/moq-net/src/util/idle.rs index 531c495c3f5..9cf51b83492 100644 --- a/rs/moq-net/src/util/idle.rs +++ b/rs/moq-net/src/util/idle.rs @@ -109,6 +109,17 @@ impl Idle { idle.parked = None; } } + + /// [`Self::disarm`] for a change made outside the read, which a gate the read nests in + /// never hears: it parked on this one and answers `Pending` again until woken. So this + /// wakes through the gate's own waiter, and every gate it nests in reads again, as does + /// the task. + pub(crate) fn reopen(this: &mut Option>) { + if let Some(idle) = this { + idle.parked = None; + idle.wake.wake_by_ref(); + } + } } #[cfg(test)] @@ -155,6 +166,44 @@ mod test { assert!(!Idle::parked(&slot, (), &other), "another task reads anew"); } + /// A reopen reaches the gate the read nests in, which parked on this one and would + /// otherwise answer `Pending` again without reading through it. A disarm does not. + #[test] + fn a_reopen_reaches_the_gates_the_read_nests_in() { + for reopen in [false, true] { + let task = Arc::new(Woken { + woken: AtomicBool::new(false), + task: Waker::noop().clone(), + }); + let waiter = kio::Waiter::new(Waker::from(task.clone())); + let mut outer_slot: Option> = None; + let mut inner_slot: Option> = None; + + // The outer read parks through the inner one, as an ordered read parks on its cursor. + let mut outer = Idle::start(&mut outer_slot, &waiter); + let inner = Idle::start(&mut inner_slot, outer.waiter()); + inner.finish(&mut inner_slot, (), true); + outer.finish(&mut outer_slot, (), true); + assert!(Idle::parked(&outer_slot, (), &waiter)); + + match reopen { + true => Idle::reopen(&mut inner_slot), + false => Idle::disarm(&mut inner_slot), + } + assert!(!Idle::parked(&inner_slot, (), &kio::Waiter::noop())); + assert_eq!( + Idle::parked(&outer_slot, (), &waiter), + !reopen, + "reopen {reopen}: the outer gate reads through" + ); + assert_eq!( + task.woken.load(Ordering::Acquire), + reopen, + "reopen {reopen}: the task wakes" + ); + } + } + /// A gate keyed by read answers only for the read that parked. #[test] fn a_parked_read_says_nothing_about_another() { From ff79f88c49034e659f4d4e4f27faadb75327499a Mon Sep 17 00:00:00 2001 From: Luke Curley Date: Wed, 18 Nov 2026 03:34:56 -0800 Subject: [PATCH 2/2] docs(moq-net): the idle module names reopen beside disarm Co-Authored-By: Claude Opus 5.5 --- rs/moq-net/src/util/idle.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rs/moq-net/src/util/idle.rs b/rs/moq-net/src/util/idle.rs index 9cf51b83492..3db5f228b5e 100644 --- a/rs/moq-net/src/util/idle.rs +++ b/rs/moq-net/src/util/idle.rs @@ -6,7 +6,8 @@ //! can answer `Pending` again without walking, and locking, everything it read before. //! //! Only what notifies can be trusted this way. A change the owner makes itself, which -//! notifies nothing, has to [`Idle::disarm`] the gate. +//! notifies nothing, has to [`Idle::disarm`] the gate, or [`Idle::reopen`] it when made +//! outside the read, so the gates it nests in and the task read again. //! //! An owner with more than one read keys each by `K`, since one parking says nothing //! about another.