From 0c348d3973b14184931a156261a731cd8b675aa1 Mon Sep 17 00:00:00 2001 From: Wanjohi Date: Sat, 17 Oct 2026 13:47:36 +0000 Subject: [PATCH] fix(neshub): a picture switch waits for the new keyframe even behind a stalled writer (#425) Follow-up to #423 from its re-review. The dgram writer now raises awaiting_keyframe when it reaches the Resubscribe marker, in queue order, and restart_picture sets the flag before queuing the marker. Before this, an old keyframe still queued ahead of a primary switch could clear the flag, letting the new picture's first delta out as the first frame an old client saw after the switch. Needs a writer stalled for at least 1 s to trigger. Tested: cargo test -p neshub on nestripc-1, 78 passed. --- apps/neshub/src/dgram.rs | 7 +++++++ apps/neshub/src/session.rs | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/apps/neshub/src/dgram.rs b/apps/neshub/src/dgram.rs index 7d401279..02bb0f9b 100644 --- a/apps/neshub/src/dgram.rs +++ b/apps/neshub/src/dgram.rs @@ -318,6 +318,13 @@ pub async fn run_datagram_writer( MediaItem::Resubscribe => { seq = 0; resync = ResyncGate::default(); + // Set here, in queue order, not only by whoever queued this: a + // keyframe from the old picture still queued ahead of it would + // otherwise clear the flag, and the new picture's first delta + // would go out as the first frame after the switch. + if let Some(ref awaiting) = awaiting_keyframe { + awaiting.store(true, Ordering::Relaxed); + } continue; } // No keyframe stream and no resync gate: every PyroWave frame diff --git a/apps/neshub/src/session.rs b/apps/neshub/src/session.rs index f8d2aac8..c615548d 100644 --- a/apps/neshub/src/session.rs +++ b/apps/neshub/src/session.rs @@ -513,10 +513,10 @@ impl ClientSession { /// zero, hold deltas until a keyframe, and forget what it reported about /// the old one. The caller asks for the keyframe. pub fn restart_picture(&self) { + self.awaiting_keyframe.store(true, Ordering::Relaxed); if self.pending_video.is_none() { let _ = self.send_video.send(MediaItem::Resubscribe); } - self.awaiting_keyframe.store(true, Ordering::Relaxed); let _ = self.take_report(); }