diff --git a/CHANGELOG.md b/CHANGELOG.md index 335890b..27f9d8f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). ### Fixed ### Removed +## 2024-05-28: v0.5.0-rc.3 +### Fixed +- Dropping admin or app connections will now close the connection. + ## 2024-05-27: v0.5.0-rc.2 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 8475e0f..6643157 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2508,7 +2508,7 @@ dependencies = [ [[package]] name = "holochain_client" -version = "0.5.0-rc.2" +version = "0.5.0-rc.3" dependencies = [ "again", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index dfef57f..5d9483a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ name = "holochain_client" readme = "README.md" repository = "https://github.com/holochain/holochain-client-rust" resolver = "2" -version = "0.5.0-rc.2" +version = "0.5.0-rc.3" [workspace] members = ["fixture/zomes/foo"] diff --git a/src/admin_websocket.rs b/src/admin_websocket.rs index 05b01e6..1ddb9e9 100644 --- a/src/admin_websocket.rs +++ b/src/admin_websocket.rs @@ -17,9 +17,11 @@ use holochain_zome_types::{ }; use serde::{Deserialize, Serialize}; use std::{net::ToSocketAddrs, sync::Arc}; +use tokio::task::JoinHandle; pub struct AdminWebsocket { tx: WebsocketSender, + poll_handle: JoinHandle<()>, } #[derive(Clone, Debug, Serialize, Deserialize)] @@ -73,9 +75,10 @@ impl AdminWebsocket { // WebsocketReceiver needs to be polled in order to receive responses // from remote to sender requests. - tokio::task::spawn(async move { while rx.recv::().await.is_ok() {} }); + let poll_handle = + tokio::task::spawn(async move { while rx.recv::().await.is_ok() {} }); - Ok(Self { tx }) + Ok(Self { tx, poll_handle }) } /// Issue an app authentication token for the specified app. @@ -334,3 +337,9 @@ impl AdminWebsocket { } } } + +impl Drop for AdminWebsocket { + fn drop(&mut self) { + self.poll_handle.abort(); + } +} diff --git a/src/app_websocket_inner.rs b/src/app_websocket_inner.rs index 40d8ada..deba92f 100644 --- a/src/app_websocket_inner.rs +++ b/src/app_websocket_inner.rs @@ -8,12 +8,14 @@ use holochain_types::signal::Signal; use holochain_websocket::{connect, WebsocketConfig, WebsocketSender}; use std::{net::ToSocketAddrs, sync::Arc}; use tokio::sync::Mutex; +use tokio::task::AbortHandle; /// The core functionality for an app websocket. #[derive(Clone)] pub(crate) struct AppWebsocketInner { tx: WebsocketSender, event_emitter: Arc>, + abort_handle: Arc, } impl AppWebsocketInner { @@ -33,7 +35,7 @@ impl AppWebsocketInner { let event_emitter = EventEmitter::new(); let mutex = Arc::new(Mutex::new(event_emitter)); - tokio::task::spawn({ + let poll_handle = tokio::task::spawn({ let mutex = mutex.clone(); async move { while let Ok(msg) = rx.recv::().await { @@ -49,6 +51,7 @@ impl AppWebsocketInner { Ok(Self { tx, event_emitter: mutex, + abort_handle: Arc::new(poll_handle.abort_handle()), }) } @@ -92,3 +95,9 @@ impl AppWebsocketInner { } } } + +impl Drop for AppWebsocketInner { + fn drop(&mut self) { + self.abort_handle.abort(); + } +}