From 6d01850866c203483bbbf40ca5b1f53aee002140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Lucas?= Date: Sat, 28 Mar 2026 19:21:21 -0300 Subject: [PATCH] fix: add #[must_use] to AbortHandle and clear message queues on disconnect - Add #[must_use] to AbortHandle so the compiler warns when a spawned task's handle is silently dropped (forces explicit .detach()) - Invalidate message_queues in cleanup_connection_state() so stale per-chat workers don't survive reconnects with outdated crypto state --- src/client.rs | 4 ++++ wacore/src/runtime.rs | 1 + 2 files changed, 5 insertions(+) diff --git a/src/client.rs b/src/client.rs index 9e09a1a75..91a014f43 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1106,6 +1106,10 @@ impl Client { // checks the socket, but this ordering avoids a confusing state window. self.is_connected.store(false, Ordering::Release); self.retried_group_messages.invalidate_all(); + // Drop per-chat message queue senders so workers exit via channel close. + // Without this, stale workers from the old connection survive reconnects + // holding outdated signal/crypto state. + self.message_queues.invalidate_all(); // Clear pending retries so stale keys from detached scopeguard // cleanup don't suppress the first retry after reconnect. self.pending_retries diff --git a/wacore/src/runtime.rs b/wacore/src/runtime.rs index 3c5f36c4f..6b866c2c0 100644 --- a/wacore/src/runtime.rs +++ b/wacore/src/runtime.rs @@ -64,6 +64,7 @@ pub trait Runtime: Send + Sync + 'static { /// Uses `std::sync::Mutex` internally so that the handle is `Send + Sync`, /// which is required because it may be stored inside structs shared across /// tasks (e.g. `NoiseSocket` behind an `Arc`). +#[must_use = "dropping an AbortHandle aborts the task; use .detach() for fire-and-forget"] pub struct AbortHandle { abort_fn: std::sync::Mutex>>, }