From b0bb6c6a9048df5c0bd7b6f9f9fb6983be30268d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sat, 24 May 2025 01:54:09 +0300 Subject: [PATCH] fix: :zap: deadlock while leaving room --- client/src/gui.rs | 20 ++++++++------------ client/src/stream.rs | 4 ++++ client/src/voice.rs | 2 +- protocol/src/lib.rs | 2 ++ 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/client/src/gui.rs b/client/src/gui.rs index 5829c59..e87e415 100644 --- a/client/src/gui.rs +++ b/client/src/gui.rs @@ -26,21 +26,17 @@ struct Signal { impl Signal { fn reset_connection(&self) -> Result<(), Error> { - if let Some(connection_signal) = self.connection_stop_sender.read().unwrap().as_ref() { - if !connection_signal.is_closed() { - let mut connection_stop_sender = self.connection_stop_sender.write().unwrap(); - connection_stop_sender - .take() - .expect("Never") - .send(true) - .unwrap(); + let connection_stop_sender = self.connection_stop_sender.write().unwrap().take(); + match connection_stop_sender { + Some(connection_stop_sender) => { + connection_stop_sender.send(true).unwrap(); - *connection_stop_sender = None; - drop(connection_stop_sender); - return Ok(()); + Ok(()) } + None => Err(Error::NotSupposeTo( + "Connection Stop Sender is None".to_string(), + ))?, } - Err(Error::Signal("Reset".to_string())) } } diff --git a/client/src/stream.rs b/client/src/stream.rs index 5e70696..307d077 100644 --- a/client/src/stream.rs +++ b/client/src/stream.rs @@ -79,8 +79,12 @@ pub async fn disconnect_watcher( ); } + println!("Going to Disconnect"); + connect_return.send_audio_task.abort(); connect_return.receive_audio_task.abort(); + + println!("Disconnected"); } async fn send_audio_data( diff --git a/client/src/voice.rs b/client/src/voice.rs index cc62ade..b309659 100644 --- a/client/src/voice.rs +++ b/client/src/voice.rs @@ -90,7 +90,7 @@ pub async fn play( }, } } else { - *sample = 0.0; + *sample = 0.0 } } }; diff --git a/protocol/src/lib.rs b/protocol/src/lib.rs index f55d996..ca3bd4d 100644 --- a/protocol/src/lib.rs +++ b/protocol/src/lib.rs @@ -16,6 +16,7 @@ pub enum Error { Signal(String), Record(String), Play(String), + NotSupposeTo(String), } impl std::error::Error for Error { @@ -34,6 +35,7 @@ impl Display for Error { Error::Signal(inner) => write!(f, "Signal | {}", inner), Error::Record(inner) => write!(f, "Record | {}", inner), Error::Play(inner) => write!(f, "Play | {}", inner), + Error::NotSupposeTo(inner) => write!(f, "Not Suppose To | {}", inner), } } }