summaryrefslogtreecommitdiffstats
path: root/crates/core/tedge_core
diff options
context:
space:
mode:
authorMatthias Beyer <matthias.beyer@ifm.com>2022-05-13 11:21:41 +0200
committerMatthias Beyer <matthias.beyer@ifm.com>2022-05-17 11:09:53 +0200
commitc2b8dd81a9ab2554ffacda1bbedbabd62d10ffc9 (patch)
tree3ef2b4a4ecc2776ba97c53424c34b3fcf4064b93 /crates/core/tedge_core
parenteea7dc38b8c3f0d2ab17879b0cedc7a0992ee3b5 (diff)
Hold read-lock as short as possible in plugin mainloop
Signed-off-by: Matthias Beyer <matthias.beyer@ifm.com>
Diffstat (limited to 'crates/core/tedge_core')
-rw-r--r--crates/core/tedge_core/src/plugin_task.rs12
1 files changed, 7 insertions, 5 deletions
diff --git a/crates/core/tedge_core/src/plugin_task.rs b/crates/core/tedge_core/src/plugin_task.rs
index 5884b277..066191ab 100644
--- a/crates/core/tedge_core/src/plugin_task.rs
+++ b/crates/core/tedge_core/src/plugin_task.rs
@@ -174,12 +174,14 @@ async fn plugin_mainloop(
let parent_span = Span::current();
tokio::spawn(async move {
- let read_plug = plug.read().await;
let handle_message_span = tracing::trace_span!(parent: parent_span, "core.plugin_task.mainloop.handle_message", msg = ?msg);
- let handled_message = std::panic::AssertUnwindSafe(read_plug.handle_message(msg))
- .catch_unwind()
- .instrument(handle_message_span)
- .await;
+ let handled_message = {
+ let read_plug = plug.read().await;
+ std::panic::AssertUnwindSafe(read_plug.handle_message(msg))
+ .catch_unwind()
+ .instrument(handle_message_span)
+ .await
+ };
match handled_message {
Err(_) => {