Skip to content

Commit

Permalink
fixed crash when closing mqtt client. set close handler to nullptr if…
Browse files Browse the repository at this point in the history
… already disconnected.
  • Loading branch information
wsobel committed Apr 12, 2024
1 parent c85b3b3 commit 0dd7ed9
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/mtconnect/mqtt/mqtt_client_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ namespace mtconnect {
{
client->async_disconnect(10s, [client, url](mqtt::error_code ec) {
LOG(warning) << url << " disconnected: " << ec.message();
client->set_close_handler(nullptr);
});

client.reset();
Expand Down Expand Up @@ -412,6 +413,13 @@ namespace mtconnect {
public:
using base = MqttClientImpl<MqttTcpClient>;
using base::base;
/// @brief Get a shared pointer to this
/// @return shared pointer to this
shared_ptr<MqttTcpClient> getptr()
{
return static_pointer_cast<MqttTcpClient>(shared_from_this());
}

/// @brief Get the Mqtt TCP Client
/// @return pointer to the Mqtt TCP Client
auto &getClient()
Expand All @@ -438,6 +446,12 @@ namespace mtconnect {
public:
using base = MqttClientImpl<MqttTlsClient>;
using base::base;
/// @brief Get a shared pointer to this
/// @return shared pointer to this
shared_ptr<MqttTlsClient> getptr()
{
return static_pointer_cast<MqttTlsClient>(shared_from_this());
}

/// @brief Get the Mqtt TLS Client
/// @return pointer to the Mqtt TLS Client
Expand Down Expand Up @@ -481,6 +495,13 @@ namespace mtconnect {
public:
using base = MqttClientImpl<MqttTlsWSClient>;
using base::base;
/// @brief Get a shared pointer to this
/// @return shared pointer to this
shared_ptr<MqttTlsWSClient> getptr()
{
return static_pointer_cast<MqttTlsWSClient>(shared_from_this());
}

/// @brief Get the Mqtt TLS WebSocket Client
/// @return pointer to the Mqtt TLS WebSocket Client
auto &getClient()
Expand Down Expand Up @@ -513,6 +534,13 @@ namespace mtconnect {
public:
using base = MqttClientImpl<MqttWSClient>;
using base::base;
/// @brief Get a shared pointer to this
/// @return shared pointer to this
shared_ptr<MqttWSClient> getptr()
{
return static_pointer_cast<MqttWSClient>(shared_from_this());
}

/// @brief Get the Mqtt TLS WebSocket Client
/// @return pointer to the Mqtt TLS WebSocket Client
auto &getClient()
Expand Down

0 comments on commit 0dd7ed9

Please sign in to comment.