diff --git a/CHANGELOG.md b/CHANGELOG.md index 2c04fdb..0d2198c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [0.4.3] Q3 2022 + - fixed panic when calling IotHubClient::from_identity_service + - fixed terminating on ExpiredSasToken + - bumped to latest azure-iot-sdk 0.8.3 + ## [0.4.2] Q3 2022 - bump to azure-iot-sdk 0.8.2 diff --git a/Cargo.lock b/Cargo.lock index 24e1d15..aa02a4b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -182,8 +182,8 @@ dependencies = [ [[package]] name = "azure-iot-sdk" -version = "0.8.2" -source = "git+ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk.git?tag=0.8.2#439595f47688cb5f3d78a7862742cbc551588cec" +version = "0.8.3" +source = "git+ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk.git?tag=0.8.3#fb30e8fd71f02b596858f24e49de5763a534dbc7" dependencies = [ "azure-iot-sdk-sys", "eis-utils", @@ -194,8 +194,8 @@ dependencies = [ [[package]] name = "azure-iot-sdk-sys" -version = "0.5.0" -source = "git+ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk-sys.git?tag=0.5.0#0acdf6a7ac32a21b57bbb44b640f91a427a30ae4" +version = "0.5.1" +source = "git+ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk-sys.git?tag=0.5.1#0024059836411a8f6b8f54f3061d31f2a2fef1db" dependencies = [ "bindgen", "pkg-config", @@ -560,7 +560,7 @@ checksum = "9be70c98951c83b8d2f8f60d7065fa6d5146873094452a1008da8c2f1e4205ad" dependencies = [ "cfg-if", "libc", - "wasi 0.10.2+wasi-snapshot-preview1", + "wasi 0.10.0+wasi-snapshot-preview1", ] [[package]] @@ -800,7 +800,7 @@ dependencies = [ [[package]] name = "iot-client-template-rs" -version = "0.4.2" +version = "0.4.3" dependencies = [ "azure-iot-sdk", "env_logger 0.8.4", @@ -1515,9 +1515,9 @@ dependencies = [ [[package]] name = "wasi" -version = "0.10.2+wasi-snapshot-preview1" +version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd6fbd9a79829dd1ad0cc20627bf1ed606756a7f77edff7b66b7064f9cb327c6" +checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" [[package]] name = "wasi" diff --git a/Cargo.toml b/Cargo.toml index e94a209..78a643a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "iot-client-template-rs" -version = "0.4.2" +version = "0.4.3" edition = "2021" authors = ["Joerg Zeidler ", "Jan Zachmann "] repository = "git@github.com:ICS-DeviceManagement/iot-client-template-rs.git" @@ -10,7 +10,7 @@ license = "MIT OR Apache-2.0" [dependencies] # use either device_client, module_client or edge_client -azure-iot-sdk = { git = "ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk.git", tag = "0.8.2", default-features = false } +azure-iot-sdk = { git = "ssh://git@github.com/ICS-DeviceManagement/azure-iot-sdk.git", tag = "0.8.3", default-features = false } sd-notify = { git = "ssh://git@github.com/ICS-DeviceManagement/sd-notify.git", tag = "v0.5.0", optional = true } serde_json = "1.0" env_logger = "0.8" diff --git a/src/client.rs b/src/client.rs index cb93a3a..9f423de 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,8 +1,8 @@ use azure_iot_sdk::client::*; use log::debug; use std::sync::{mpsc::Receiver, mpsc::Sender, Arc, Mutex}; -use tokio::task::JoinHandle; use std::time; +use tokio::task::JoinHandle; #[cfg(feature = "systemd")] use crate::systemd::WatchdogHandler; @@ -81,7 +81,7 @@ impl Client { let running = Arc::clone(&self.run); - self.thread = Some(tokio::spawn(async move { + self.thread = Some(tokio::task::spawn_blocking(move || { let hundred_millis = time::Duration::from_millis(100); let event_handler = ClientEventHandler { direct_methods, tx }; @@ -92,10 +92,9 @@ impl Client { wdt.init()?; let mut client = match IotHubClient::get_client_type() { - _ if connection_string.is_some() => IotHubClient::from_connection_string( - connection_string.unwrap(), - event_handler, - )?, + _ if connection_string.is_some() => { + IotHubClient::from_connection_string(connection_string.unwrap(), event_handler)? + } ClientType::Device | ClientType::Module => { IotHubClient::from_identity_service(event_handler)? } diff --git a/src/lib.rs b/src/lib.rs index c3c8adb..6a36de3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,8 +7,12 @@ pub mod twin; use azure_iot_sdk::client::*; use client::{Client, Message}; use log::{debug, error}; +use std::matches; +use std::sync::Once; use std::sync::{mpsc, Arc, Mutex}; +static INIT: Once = Once::new(); + #[tokio::main] pub async fn run() -> Result<(), IotError> { let mut client = Client::new(); @@ -22,19 +26,23 @@ pub async fn run() -> Result<(), IotError> { for msg in rx_client2app { match msg { Message::Authenticated => { - #[cfg(feature = "systemd")] - systemd::notify_ready(); + INIT.call_once(|| { + #[cfg(feature = "systemd")] + systemd::notify_ready(); - if let Err(e) = twin::report_version(Arc::clone(&tx_app2client)) { - error!("Couldn't report version: {}", e); - } + if let Err(e) = twin::report_version(Arc::clone(&tx_app2client)) { + error!("Couldn't report version: {}", e); + } + }); } Message::Unauthenticated(reason) => { - client.stop().await.unwrap(); - return Err(IotError::from(format!( - "No connection. Reason: {:?}", - reason - ))); + if !matches!(reason, UnauthenticatedReason::ExpiredSasToken) { + client.stop().await.unwrap(); + return Err(IotError::from(format!( + "No connection. Reason: {:?}", + reason + ))); + } } Message::Desired(state, desired) => { twin::update(state, desired, Arc::clone(&tx_app2client));