diff --git a/services/tunnelbroker/src/Amqp/AmqpManager.h b/services/tunnelbroker/src/Amqp/AmqpManager.h --- a/services/tunnelbroker/src/Amqp/AmqpManager.h +++ b/services/tunnelbroker/src/Amqp/AmqpManager.h @@ -7,6 +7,7 @@ #include #include +#include #include namespace comm { @@ -15,6 +16,7 @@ class AmqpManager { AmqpManager(){}; + std::mutex channelMutex; std::once_flag initOnceFlag; std::unique_ptr amqpChannel; std::atomic amqpReady; diff --git a/services/tunnelbroker/src/Amqp/AmqpManager.cpp b/services/tunnelbroker/src/Amqp/AmqpManager.cpp --- a/services/tunnelbroker/src/Amqp/AmqpManager.cpp +++ b/services/tunnelbroker/src/Amqp/AmqpManager.cpp @@ -123,6 +123,8 @@ // Set delivery mode to: Durable (2) env.setDeliveryMode(2); env.setHeaders(std::move(headers)); + + std::scoped_lock lock{this->channelMutex}; this->amqpChannel->publish( config::ConfigManager::getInstance().getParameter( config::ConfigManager::OPTION_AMQP_FANOUT_EXCHANGE), @@ -137,6 +139,7 @@ void AmqpManager::ack(uint64_t deliveryTag) { waitUntilReady(); + std::scoped_lock lock{this->channelMutex}; this->amqpChannel->ack(deliveryTag); }