summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-08-26 15:58:35 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-08-30 13:54:48 +0200
commite34e9dc6290b993e206dc5c2141559ef3ac744bb (patch)
treecfefebf1e1909322187bfc328b46f4306545e600
parent7e91080f39c518db20d1e768b294e6ed568de290 (diff)
Implement PanicStrategy::Shutdownpost-merge/panic-strategies
This patch implements the handling of a `panic_strategy = "shutdown"` configuration, where thin-edge.io should shut down if one plugin panics. Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
-rw-r--r--crates/core/tedge_core/src/reactor.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/crates/core/tedge_core/src/reactor.rs b/crates/core/tedge_core/src/reactor.rs
index f845335c..2448689c 100644
--- a/crates/core/tedge_core/src/reactor.rs
+++ b/crates/core/tedge_core/src/reactor.rs
@@ -21,6 +21,7 @@ use crate::communication::CorePluginDirectory;
use crate::communication::PluginDirectory;
use crate::communication::PluginInfo;
use crate::configuration::InstanceConfiguration;
+use crate::configuration::PanicStrategy;
use crate::configuration::PluginInstanceConfiguration;
use crate::configuration::PluginKind;
use crate::core_task::CoreInternalMessage;
@@ -214,12 +215,16 @@ impl Reactor {
debug!("Running 'main' for plugins");
{
let main_cancellation = Arc::new(CancellationToken::new());
+ let panic_strategy = self.0.config().panic_strategy();
let _main_results = all_plugins
.iter_mut()
.map(|plugin_task| {
+ let main_cancellation = main_cancellation.clone();
let cancellation_token = main_cancellation.child_token();
async {
+ let main_cancellation = main_cancellation;
let cancellation_token = cancellation_token;
+ let panic_strategy = panic_strategy;
let mut restarted_once = false;
loop {
let span =
@@ -227,11 +232,17 @@ impl Reactor {
tokio::select! {
_cancelled = cancellation_token.cancelled() => {
- // Nothing for now
+ debug!(plugin_name = plugin_task.plugin_name(), "Received cancellation. Stopped execution of plugin main()");
+ break;
},
main_result = plugin_task.run_main().instrument(span) => {
match main_result {
err @ Err(crate::errors::PluginLifecycleError::PluginMainPanicked(_)) => {
+ if panic_strategy == PanicStrategy::Shutdown {
+ main_cancellation.cancel();
+ break;
+ }
+
let restart_policy = self.0.config().plugins().get(plugin_task.plugin_name())
.map(|pl| pl.restart_policy());