Skip to content

Commit

Permalink
fix: stop OperationHandler spawning extra tasks
Browse files Browse the repository at this point in the history
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 <marcel.guzik@inetum.com>
  • Loading branch information
Bravo555 committed Aug 1, 2024
1 parent 04e63ee commit be3b850
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion crates/extensions/c8y_mapper_ext/src/operations/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit be3b850

Please sign in to comment.