fix(relay): keep a reconnected device online when its stale connection times out

After a network change (Wi-Fi to mobile data) the app reconnects right
away, while the relay only notices the old connection is dead once the
idle timeout expires. When that stale handler finally exited it removed
the device from the online map by address alone, which dropped the new,
healthy connection. From then on every message was stored as offline and
only a push wake-up could fetch it, even though the app was connected.

The online map is now its own type: a newly authenticated connection
takes over delivery for the address, and a closing connection removes
the entry only if it still points at itself. Tests cover the registry
and the full route after a stale connection ends.
This commit is contained in:
Julius Joska
2026-09-29 18:30:11 +02:00
parent bd51fef5cc
commit e5d0e54b80
2 changed files with 120 additions and 8 deletions
+3 -3
View File
@@ -276,7 +276,7 @@ async fn handle(state: Arc<AppState>, socket: WebSocket) {
));
state
.online
.insert(pd.delivery_address.clone(), device.clone());
.attach(pd.delivery_address.clone(), device.clone());
online_device = Some(device);
authed_address = Some(pd.delivery_address.clone());
@@ -360,8 +360,8 @@ async fn handle(state: Arc<AppState>, socket: WebSocket) {
}
}
if let Some(addr) = authed_address {
state.online.remove(&addr);
if let (Some(addr), Some(device)) = (&authed_address, &online_device) {
state.online.detach(addr, device);
}
writer.abort();
tracing::debug!("ws spojení uzavřeno");