From 0d129e1d53236aba2e375dfc385d23250f7f3f2c Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Tue, 28 May 2024 11:17:34 +0100 Subject: [PATCH 1/3] Dropping connection does not close it --- CHANGELOG.md | 4 ++++ src/admin_websocket.rs | 12 ++++++++++-- src/app_websocket_inner.rs | 11 ++++++++++- 3 files changed, 24 insertions(+), 3 deletions(-) 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/src/admin_websocket.rs b/src/admin_websocket.rs index 05b01e6..00a3a93 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,9 @@ 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 +336,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(); + } +} From b844aef3658c27657c5a2744bf417105d2922990 Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Tue, 28 May 2024 11:26:17 +0100 Subject: [PATCH 2/3] Bump version --- Cargo.lock | 2 +- Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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"] From 05a8b8f3fad75763c086649b35a1fefed71093fd Mon Sep 17 00:00:00 2001 From: ThetaSinner Date: Tue, 28 May 2024 11:44:39 +0100 Subject: [PATCH 3/3] Format --- src/admin_websocket.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/admin_websocket.rs b/src/admin_websocket.rs index 00a3a93..1ddb9e9 100644 --- a/src/admin_websocket.rs +++ b/src/admin_websocket.rs @@ -75,7 +75,8 @@ impl AdminWebsocket { // WebsocketReceiver needs to be polled in order to receive responses // from remote to sender requests. - let poll_handle = 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, poll_handle }) }