Skip to content

Commit

Permalink
Merge pull request #2631 from didier-wenzek/fix/tedge-agent-restart-o…
Browse files Browse the repository at this point in the history
…n-self-update

Fix tedge agent restart on self update
  • Loading branch information
didier-wenzek authored Jan 30, 2024
2 parents 6d4a00f + 69cce99 commit 00c14eb
Show file tree
Hide file tree
Showing 23 changed files with 58 additions and 43 deletions.
6 changes: 6 additions & 0 deletions crates/core/tedge_actors/src/message_boxes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,12 @@ impl<Input: Debug> LoggingReceiver<Input> {
pub fn into_split(self) -> (mpsc::Receiver<Input>, mpsc::Receiver<RuntimeRequest>) {
(self.receiver.input_receiver, self.receiver.signal_receiver)
}

/// Close the input so no new messages can be sent to this receiver
pub fn close_input(&mut self) {
self.receiver.input_receiver.close();
self.receiver.signal_receiver.close();
}
}

#[async_trait]
Expand Down
3 changes: 3 additions & 0 deletions crates/core/tedge_agent/src/software_manager/actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use serde::Deserialize;
use serde::Serialize;
use std::path::PathBuf;
use std::process::Command;
use std::time::Duration;
use tedge_actors::fan_in_message_type;
use tedge_actors::Actor;
use tedge_actors::LoggingReceiver;
Expand Down Expand Up @@ -107,6 +108,8 @@ impl Actor for SoftwareManagerActor {
_ = self.handle_request(request, &mut plugins, &operation_logs) => {
if let Err(SoftwareManagerError::NotRunningLatestVersion) = Self::detect_self_update() {
error!("Tedge-agent is no more running the latest-version => a restart is required");
// Make sure the operation status is properly reported before the restart
tokio::time::sleep(Duration::from_secs(5)).await;
return Err(RuntimeError::ActorError(Box::new(SoftwareManagerError::NotRunningLatestVersion)));
}
}
Expand Down
16 changes: 11 additions & 5 deletions crates/extensions/tedge_mqtt_ext/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,18 @@ impl FromPeers {
&mut self,
outgoing_mqtt: &mut mpsc::UnboundedSender<MqttMessage>,
) -> Result<(), RuntimeError> {
loop {
match self.try_recv().await {
Ok(Some(message)) => outgoing_mqtt.send(message).await.map_err(Box::new)?,
Ok(None) | Err(RuntimeRequest::Shutdown) => break Ok(()),
}
while let Ok(Some(message)) = self.try_recv().await {
outgoing_mqtt.send(message).await.map_err(Box::new)?;
}

// On shutdown, first close input so no new messages can be pushed
self.input_receiver.close_input();

// Then, publish all the messages awaiting to be sent over MQTT
while let Some(message) = self.recv().await {
outgoing_mqtt.send(message).await.map_err(Box::new)?;
}
Ok(())
}
}

Expand Down
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown
Git LFS file not shown

1 comment on commit 00c14eb

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Robot Results

✅ Passed ❌ Failed ⏭️ Skipped Total Pass % ⏱️ Duration
384 0 3 384 100 53m57.173s

Please sign in to comment.