From cf6157af0953779c3a875337c0f098289ab72b9c Mon Sep 17 00:00:00 2001 From: David Date: Tue, 24 Nov 2026 00:36:32 +0000 Subject: [PATCH] acphal: a reconnect drops messages queued for the old channel Channel::connect() left self.messages alone, so a MSG_DISCONNECTED (or stale command acks) queued before a disconnect surfaced on the fresh connection. Clear the queue on connect. Part of #329. Assisted-by: Devin (SWE-2 Flash Medium) --- crates/xcl/src/hle/acphal.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/crates/xcl/src/hle/acphal.rs b/crates/xcl/src/hle/acphal.rs index 2210066f1..83caef448 100644 --- a/crates/xcl/src/hle/acphal.rs +++ b/crates/xcl/src/hle/acphal.rs @@ -499,6 +499,9 @@ pub struct Channel { impl Channel { pub fn connect(&mut self, now: Instant) { self.connected = true; + // A reconnect starts a fresh channel: messages queued for the old one + // (a MSG_DISCONNECT nobody popped, stale command acks) must not surface. + self.messages.clear(); self.next_frame = Some(now + FRAME); } @@ -1137,6 +1140,18 @@ mod tests { assert_eq!(c.pop(later).map(|m| m.kind), Some(MSG_DISCONNECTED)); } + #[test] + fn reconnect_drops_messages_queued_for_the_old_channel() { + let t0 = Instant::now(); + let mut c = Channel::default(); + c.connect(t0); + c.disconnect(); // queues MSG_DISCONNECTED; the title never pops it + c.connect(t0); + assert_eq!(c.pop(t0), None, "the stale disconnect must not surface on the new channel"); + let later = t0 + FRAME * 3; + assert_eq!(c.pop(later).map(|m| m.kind), Some(MSG_AUDIO_FRAME)); + } + #[test] fn decoder_returns_silence() { unsafe {