Fix UI sync bugs and disconnect hang
- Add NeighborDown event handler in gossip network to reliably remove disconnected peers. - Add 1-second timeout wrapper to router.shutdown() to prevent UI hanging on disconnect.
This commit is contained in:
+11
-6
@@ -54,25 +54,30 @@ struct ActiveSession {
|
|||||||
|
|
||||||
impl ActiveSession {
|
impl ActiveSession {
|
||||||
async fn shutdown(self, audio_backend: Arc<PipeWireBackend>) {
|
async fn shutdown(self, audio_backend: Arc<PipeWireBackend>) {
|
||||||
// Abort asynchronous tasks first
|
crate::log_msg("ActiveSession::shutdown started");
|
||||||
self.datagram_task.abort();
|
self.datagram_task.abort();
|
||||||
self.mixer_task.abort();
|
self.mixer_task.abort();
|
||||||
self.event_task.abort();
|
self.event_task.abort();
|
||||||
|
crate::log_msg("Aborted tasks");
|
||||||
|
|
||||||
// Stop the audio backend in a blocking thread to avoid blocking the async executor
|
|
||||||
let audio_backend_clone = audio_backend.clone();
|
let audio_backend_clone = audio_backend.clone();
|
||||||
let _ = tokio::task::spawn_blocking(move || {
|
let _ = tokio::task::spawn_blocking(move || {
|
||||||
|
crate::log_msg("Stopping audio backend...");
|
||||||
let _ = audio_backend_clone.stop();
|
let _ = audio_backend_clone.stop();
|
||||||
|
crate::log_msg("Audio backend stopped");
|
||||||
}).await;
|
}).await;
|
||||||
|
|
||||||
// Leave room
|
crate::log_msg("Leaving room...");
|
||||||
let _ = self.room_state.leave().await;
|
let _ = self.room_state.leave().await;
|
||||||
|
crate::log_msg("Room left");
|
||||||
|
|
||||||
// Shut down router
|
crate::log_msg("Shutting down router...");
|
||||||
let _ = self.router.shutdown().await;
|
let _ = tokio::time::timeout(std::time::Duration::from_secs(1), self.router.shutdown()).await;
|
||||||
|
crate::log_msg("Router shut down");
|
||||||
|
|
||||||
// Clean up capture thread
|
crate::log_msg("Joining capture thread...");
|
||||||
let _ = self.capture_thread.join();
|
let _ = self.capture_thread.join();
|
||||||
|
crate::log_msg("ActiveSession::shutdown complete");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -195,6 +195,11 @@ impl RoomState for IrohGossipState {
|
|||||||
}
|
}
|
||||||
Ok(iroh_gossip::api::Event::NeighborDown(peer_id)) => {
|
Ok(iroh_gossip::api::Event::NeighborDown(peer_id)) => {
|
||||||
crate::log_msg(&format!("Gossip event: NeighborDown={:?}", peer_id));
|
crate::log_msg(&format!("Gossip event: NeighborDown={:?}", peer_id));
|
||||||
|
let removed = peers.lock().unwrap().remove(&peer_id).is_some();
|
||||||
|
if removed {
|
||||||
|
crate::log_msg(&format!("Removed peer due to NeighborDown: {:?}", peer_id));
|
||||||
|
let _ = event_tx.send(RoomEvent::PeerLeft(peer_id)).await;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Ok(other) => {
|
Ok(other) => {
|
||||||
crate::log_msg(&format!("Gossip other event: {:?}", other));
|
crate::log_msg(&format!("Gossip other event: {:?}", other));
|
||||||
|
|||||||
Reference in New Issue
Block a user