From 10aabbb483dfa1408eb676bca2e50065c1be5520 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Korina=20=C5=A0imi=C4=8Devi=C4=87?= Date: Mon, 12 Feb 2024 15:19:55 +0100 Subject: [PATCH] Do not unlock the connection mutex if the operation was cancelled Summary: related to T11798 Reviewers: ivica Reviewed By: ivica Subscribers: iljazovic, miljen Differential Revision: https://repo.mireo.local/D27877 --- include/async_mqtt5/impl/reconnect_op.hpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/include/async_mqtt5/impl/reconnect_op.hpp b/include/async_mqtt5/impl/reconnect_op.hpp index 44ad62a..b2d7782 100644 --- a/include/async_mqtt5/impl/reconnect_op.hpp +++ b/include/async_mqtt5/impl/reconnect_op.hpp @@ -67,7 +67,11 @@ public: } void operator()(on_locked, typename Owner::stream_ptr s, error_code ec) { - if (ec == asio::error::operation_aborted || !_owner.is_open()) + if (ec == asio::error::operation_aborted) + // cancelled without acquiring the lock (by calling client.cancel()) + return std::move(_handler)(ec); + + if (!_owner.is_open()) return complete(asio::error::operation_aborted); if (s != _owner._stream_ptr) @@ -182,8 +186,7 @@ private: void complete(error_code ec) { get_cancellation_slot().clear(); - if (ec != asio::error::operation_aborted) - _owner._conn_mtx.unlock(); + _owner._conn_mtx.unlock(); std::move(_handler)(ec); }