diff --git a/Cargo.lock b/Cargo.lock index 0962c69..0e4fe57 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -499,9 +499,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.5.0" +version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" [[package]] name = "aws-lc-rs" @@ -2917,9 +2917,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.149" +version = "1.0.150" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" dependencies = [ "itoa", "memchr", @@ -3608,7 +3608,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "ttp-core" version = "0.1.0" -source = "git+https://git.methanium.net/Tensamin/TTP.git#3e3f939f64088cb01c13348b58c504593953ec0e" +source = "git+https://git.methanium.net/Tensamin/TTP.git#886edbf51d26636e46745c3637b80610df82f5dc" dependencies = [ "base64", "byteorder", @@ -3621,7 +3621,7 @@ dependencies = [ [[package]] name = "ttp-native" version = "0.1.0" -source = "git+https://git.methanium.net/Tensamin/TTP.git#3e3f939f64088cb01c13348b58c504593953ec0e" +source = "git+https://git.methanium.net/Tensamin/TTP.git#886edbf51d26636e46745c3637b80610df82f5dc" dependencies = [ "quinn", "rustls", diff --git a/src/main.rs b/src/main.rs index f92ccc4..40bf10a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -44,14 +44,14 @@ async fn main() { .and_then(|s| s.parse().ok()) .unwrap_or(9187); - tokio::spawn(async move { + let omikron_handle = tokio::spawn(async move { match omikron_connection::start(omikron_port).await { Err(e) => log_err!(0, PrintType::General, "{:?}", e), _ => {} } }); - tokio::spawn(async move { + let tauri_handle = tokio::spawn(async move { match tauri::start(9189).await { Err(e) => log_err!(0, PrintType::General, "{:?}", e), _ => {} @@ -80,7 +80,17 @@ async fn main() { .and_then(|s| s.parse().ok()) .unwrap_or(9188); - let _ = server::server::start(api_port).await; + tokio::select! { + result = server::server::start(api_port) => { + if let Err(e) = result { + log_err!(0, PrintType::General, "Server error: {:?}", e); + } + } + _ = tokio::signal::ctrl_c() => { + log!("Shutting down on signal..."); + } + } - tokio::signal::ctrl_c().await.unwrap(); + omikron_handle.abort(); + tauri_handle.abort(); } diff --git a/src/transport/omikron_connection.rs b/src/transport/omikron_connection.rs index a3dd099..acb0bff 100644 --- a/src/transport/omikron_connection.rs +++ b/src/transport/omikron_connection.rs @@ -103,7 +103,15 @@ pub struct OmikronConnection { pub_key: RwLock>>, pub ping: RwLock, waiting_tasks: DashMap, - cleanup_handle: Mutex>>, + cleanup_handle: std::sync::Mutex>>, +} + +impl Drop for OmikronConnection { + fn drop(&mut self) { + if let Some(handle) = self.cleanup_handle.lock().unwrap().take() { + handle.abort(); + } + } } impl OmikronConnection { @@ -120,7 +128,7 @@ impl OmikronConnection { pub_key: RwLock::new(None), ping: RwLock::new(-1), waiting_tasks: DashMap::new(), - cleanup_handle: Mutex::new(None), + cleanup_handle: std::sync::Mutex::new(None), }); conn @@ -148,7 +156,7 @@ impl OmikronConnection { .retain(|_, v| v.inserted_at.elapsed() < MAX_WAITING_AGE); } }); - *self.cleanup_handle.lock().await = Some(cleanup_handle); + *self.cleanup_handle.lock().unwrap() = Some(cleanup_handle); while let Ok(cv) = receiver.receive().await { if let Err(e) = self.clone().process_message(cv).await { @@ -1114,8 +1122,7 @@ impl OmikronConnection { } } - // Cancel cleanup task - if let Some(handle) = self.cleanup_handle.lock().await.take() { + if let Some(handle) = self.cleanup_handle.lock().unwrap().take() { handle.abort(); } }