Skip to content

Commit

Permalink
Merge pull request #78 from holochain/0.3-dropping-connection-does-no…
Browse files Browse the repository at this point in the history
…t-close-it

0.3 dropping connection does not close it
  • Loading branch information
ThetaSinner authored May 28, 2024
2 parents f064d89 + 05a8b8f commit c61df5d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 11 additions & 2 deletions src/admin_websocket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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::<AdminResponse>().await.is_ok() {} });
let poll_handle =
tokio::task::spawn(async move { while rx.recv::<AdminResponse>().await.is_ok() {} });

Ok(Self { tx })
Ok(Self { tx, poll_handle })
}

/// Issue an app authentication token for the specified app.
Expand Down Expand Up @@ -334,3 +337,9 @@ impl AdminWebsocket {
}
}
}

impl Drop for AdminWebsocket {
fn drop(&mut self) {
self.poll_handle.abort();
}
}
11 changes: 10 additions & 1 deletion src/app_websocket_inner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Mutex<EventEmitter>>,
abort_handle: Arc<AbortHandle>,
}

impl AppWebsocketInner {
Expand All @@ -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::<AppResponse>().await {
Expand All @@ -49,6 +51,7 @@ impl AppWebsocketInner {
Ok(Self {
tx,
event_emitter: mutex,
abort_handle: Arc::new(poll_handle.abort_handle()),
})
}

Expand Down Expand Up @@ -92,3 +95,9 @@ impl AppWebsocketInner {
}
}
}

impl Drop for AppWebsocketInner {
fn drop(&mut self) {
self.abort_handle.abort();
}
}

0 comments on commit c61df5d

Please sign in to comment.