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 @@ -15,6 +15,7 @@ class AmqpManager { AmqpManager(){}; + std::mutex channelMutex; std::unique_ptr amqpChannel; std::atomic amqpReady; std::atomic lastConnectionTimestamp; 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 @@ -131,6 +131,8 @@ // Set delivery mode to: Durable (2) env.setDeliveryMode(2); env.setHeaders(std::move(headers)); + + std::scoped_lock(this->channelMutex); this->amqpChannel->publish( config::ConfigManager::getInstance().getParameter( config::ConfigManager::OPTION_AMQP_FANOUT_EXCHANGE), @@ -145,6 +147,7 @@ void AmqpManager::ack(uint64_t deliveryTag) { waitUntilReady(); + std::scoped_lock(this->channelMutex); this->amqpChannel->ack(deliveryTag); }