-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
adds second kuksa client in zenoh-kuksa-provider #10
adds second kuksa client in zenoh-kuksa-provider #10
Conversation
@max-grzanna what do you think? |
I ran into a deadlock where the task with the function The approach of locking the client whenever one actually wants to send something might fall short too, when the kuksa_client is occupied by waiting on the subscription in the |
Instantiating a second client works for me. I can't think of a better option either. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments
zenoh-kuksa-provider/Cargo.toml
Outdated
@@ -12,6 +12,8 @@ | |||
######################################################################## | |||
|
|||
|
|||
[workspace] | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not needed
@@ -123,7 +121,7 @@ async fn publish_to_zenoh( | |||
let vss_path = &entry.path; | |||
|
|||
if let Some(publisher) = publishers.get(vss_path.as_str()) { | |||
let buf = match datapoint_to_string(&datapoint) { | |||
let buf = match datapoint_to_string(datapoint) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please keep using the reference
I think dropping the sub_client in the |
Okay, might not solve it entirely since you're blocking with a while loop after subscribing to databroker. As you described not what you want yes so keep using two clients in this case. Nonetheless some comments about the implementation. |
zenoh-kuksa-provider/src/main.rs
Outdated
@@ -182,7 +180,8 @@ async fn main() { | |||
|
|||
let uri = kuksa::Uri::try_from(provider_config.kuksa.databroker_url.as_str()) | |||
.expect("Invalid URI for Kuksa Databroker connection."); | |||
let client = Arc::new(Mutex::new(kuksa::Client::new(uri))); | |||
let client = Arc::new(Mutex::new(kuksa::Client::new(uri.clone()))); | |||
let actuation_client = kuksa::Client::new(uri); | |||
|
|||
fetch_metadata( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
since you await this function you do not need to have a
let client = Arc::new(Mutex::new(kuksa::Client::new(uri.clone())));
zenoh-kuksa-provider/src/main.rs
Outdated
@@ -182,7 +180,8 @@ async fn main() { | |||
|
|||
let uri = kuksa::Uri::try_from(provider_config.kuksa.databroker_url.as_str()) | |||
.expect("Invalid URI for Kuksa Databroker connection."); | |||
let client = Arc::new(Mutex::new(kuksa::Client::new(uri))); | |||
let client = Arc::new(Mutex::new(kuksa::Client::new(uri.clone()))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let client = kuksa::Client::new(uri.clone());
zenoh-kuksa-provider/src/main.rs
Outdated
@@ -182,7 +180,8 @@ async fn main() { | |||
|
|||
let uri = kuksa::Uri::try_from(provider_config.kuksa.databroker_url.as_str()) | |||
.expect("Invalid URI for Kuksa Databroker connection."); | |||
let client = Arc::new(Mutex::new(kuksa::Client::new(uri))); | |||
let client = Arc::new(Mutex::new(kuksa::Client::new(uri.clone()))); | |||
let actuation_client = kuksa::Client::new(uri); | |||
|
|||
fetch_metadata( | |||
client.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use a reference here instead
} | ||
} | ||
} | ||
|
||
async fn publish_to_zenoh( | ||
provider_config: Arc<ProviderConfig>, | ||
session: Arc<Session>, | ||
kuksa_client: Arc<Mutex<kuksa::Client>>, | ||
mut kuksa_client: kuksa::Client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use reference. mut not needed since you're not editing the client
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is necessary to have a mutable client because the implementation for the functions requires a mutable reference for self.
pub async fn subscribe_target_values(
&mut self,
paths: Vec<&str>,
Correct me if I'm wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will check if mut
is necessary there, but yes you're right. Nice catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked it is necessary so all good here
@@ -55,8 +55,6 @@ async fn handling_zenoh_subscribtion( | |||
) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use reference for kuksa_client
@lukasmittag I pushed a new commit, could you please have another look at some time. Sorry for the delay, I was on business trip this week. |
} | ||
} | ||
} | ||
|
||
async fn publish_to_zenoh( | ||
provider_config: Arc<ProviderConfig>, | ||
session: Arc<Session>, | ||
kuksa_client: Arc<Mutex<kuksa::Client>>, | ||
mut kuksa_client: kuksa::Client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've checked it is necessary so all good here
paths: Vec<&str>, | ||
metadata_store: &super::metadata_store::MetadataStore, | ||
) { | ||
let mut client = kuksa_client.lock().await; | ||
) -> Client { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should not return anything here right?
@@ -40,6 +39,8 @@ pub async fn fetch_metadata( | |||
}, | |||
); | |||
} | |||
|
|||
kuksa_client |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unnecessary to return this
fetch_metadata( | ||
client.clone(), | ||
client = fetch_metadata( | ||
client, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should work if you give a reference or clone the client
To avoid a deadlock between waiting for the kuksa subscription and sending messages on the same client, a second client gets initialized. In addition, some clippy warning get fixed.
e9af139
to
62f4012
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good enough to be merged. Note: TODO - check if mutable is really necessary in rust lib of kuksa
To avoid a deadlock between waiting for the kuksa subscription and sending messages on the same client, a second client gets initialized. In addition, some clippy warning get fixed.