From be3b850717f40d28a0a960aae2d5bd356ca1e3a1 Mon Sep 17 00:00:00 2001 From: Marcel Guzik Date: Thu, 1 Aug 2024 18:46:55 +0200 Subject: [PATCH] fix: stop OperationHandler spawning extra tasks When receiving multiple MQTT messages on a command topic, `OperationHandler::handle` method spawned extra tokio tasks, because `.unwrap_or` and not `.unwrap_or_else` was used when checking if a task for that topic already existed. Fortunately because returned object, and along it the sender to the task, was immediately dropped, the task exited and so we weren't leaking anything. Signed-off-by: Marcel Guzik --- crates/extensions/c8y_mapper_ext/src/operations/handler.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/extensions/c8y_mapper_ext/src/operations/handler.rs b/crates/extensions/c8y_mapper_ext/src/operations/handler.rs index b930d3b8d4a..1850f2c51d7 100644 --- a/crates/extensions/c8y_mapper_ext/src/operations/handler.rs +++ b/crates/extensions/c8y_mapper_ext/src/operations/handler.rs @@ -138,7 +138,7 @@ impl OperationHandler { let running_operation = self.running_operations.remove(&topic); let running_operation = - running_operation.unwrap_or(RunningOperation::spawn(Arc::clone(&self.context))); + running_operation.unwrap_or_else(|| RunningOperation::spawn(Arc::clone(&self.context))); let operation_status = running_operation .update(message)