diff --git a/cluster_client.cpp b/cluster_client.cpp index c88f25dc..d9868c74 100644 --- a/cluster_client.cpp +++ b/cluster_client.cpp @@ -59,13 +59,24 @@ cluster_client_t::cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd st_cli.parse_config(config); st_cli.load_global_config(); - consumer.loop = [this]() + if (ringloop) { - msgr.read_requests(); - msgr.send_replies(); - this->ringloop->submit(); - }; - ringloop->register_consumer(&consumer); + consumer.loop = [this]() + { + msgr.read_requests(); + msgr.send_replies(); + this->ringloop->submit(); + }; + ringloop->register_consumer(&consumer); + } +} + +cluster_client_t::~cluster_client_t() +{ + if (ringloop) + { + ringloop->unregister_consumer(&consumer); + } } void cluster_client_t::continue_ops() diff --git a/cluster_client.h b/cluster_client.h index 258ded36..80b4d43a 100644 --- a/cluster_client.h +++ b/cluster_client.h @@ -78,6 +78,7 @@ class cluster_client_t public: cluster_client_t(ring_loop_t *ringloop, timerfd_manager_t *tfd, json11::Json & config); + ~cluster_client_t(); void execute(cluster_op_t *op); protected: diff --git a/messenger.cpp b/messenger.cpp index a44aaf7c..9d620a38 100644 --- a/messenger.cpp +++ b/messenger.cpp @@ -22,6 +22,14 @@ osd_op_t::~osd_op_t() } } +osd_messenger_t::~osd_messenger_t() +{ + while (clients.size() > 0) + { + stop_client(clients.begin()->first); + } +} + void osd_messenger_t::connect_peer(uint64_t peer_osd, json11::Json peer_state) { if (wanted_peers.find(peer_osd) == wanted_peers.end()) diff --git a/messenger.h b/messenger.h index 4dcf6ecd..7dc85964 100644 --- a/messenger.h +++ b/messenger.h @@ -257,6 +257,7 @@ public: void read_requests(); void send_replies(); void accept_connections(int listen_fd); + ~osd_messenger_t(); protected: void try_connect_peer(uint64_t osd_num);