Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

- fixed panic when calling IotHubClient::from_identity_service #23

Merged
merged 2 commits into from
Jul 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

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

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "iot-client-template-rs"
version = "0.4.2"
version = "0.4.3"
edition = "2021"
authors = ["Joerg Zeidler <joerg.zeidler@conplement.de>", "Jan Zachmann <jan.zachmann@conplement.de>"]
repository = "git@github.com:ICS-DeviceManagement/iot-client-template-rs.git"
Expand All @@ -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"
Expand Down
11 changes: 5 additions & 6 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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 };

Expand All @@ -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)?
}
Expand Down
28 changes: 18 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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));
Expand Down