From fa1ddfea12781cf8817af5c0d09ccf15bf457aff Mon Sep 17 00:00:00 2001 From: Tyler Neely Date: Wed, 2 Nov 2022 17:45:27 +0000 Subject: [PATCH] Fix a bug where the MachineManager's destructor became incorrect after being moved --- src/coordinator/coordinator_worker.hpp | 3 ++- src/machine_manager/machine_manager.hpp | 8 ++++---- src/storage/v3/shard_worker.hpp | 1 + 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/coordinator/coordinator_worker.hpp b/src/coordinator/coordinator_worker.hpp index b89a9c496..46ca39b02 100644 --- a/src/coordinator/coordinator_worker.hpp +++ b/src/coordinator/coordinator_worker.hpp @@ -88,6 +88,7 @@ class Queue { public: void Push(Message &&message) { { + MG_ASSERT(inner_.use_count() > 0); std::unique_lock lock(inner_->mu); inner_->queue.emplace_back(std::forward(message)); @@ -132,7 +133,7 @@ class CoordinatorWorker { public: CoordinatorWorker(io::Io io, Queue queue, Coordinator coordinator) - : io_(io), queue_(queue), coordinator_{std::move(io.ForkLocal()), {}, std::move(coordinator)} {} + : io_(io), queue_(std::move(queue)), coordinator_{std::move(io.ForkLocal()), {}, std::move(coordinator)} {} CoordinatorWorker(CoordinatorWorker &&) = default; CoordinatorWorker &operator=(CoordinatorWorker &&) = default; diff --git a/src/machine_manager/machine_manager.hpp b/src/machine_manager/machine_manager.hpp index 75dd0d564..2bbc99441 100644 --- a/src/machine_manager/machine_manager.hpp +++ b/src/machine_manager/machine_manager.hpp @@ -92,10 +92,10 @@ class MachineManager { MachineManager &operator=(const MachineManager &) = delete; ~MachineManager() { - coordinator_queue_.Push(coordinator::coordinator_worker::ShutDown{}); - spdlog::error("a"); - std::move(coordinator_handle_).join(); - spdlog::error("b"); + if (coordinator_handle_.joinable()) { + coordinator_queue_.Push(coordinator::coordinator_worker::ShutDown{}); + std::move(coordinator_handle_).join(); + } } Address CoordinatorAddress() { return coordinator_address_; } diff --git a/src/storage/v3/shard_worker.hpp b/src/storage/v3/shard_worker.hpp index 4cca118e7..b1fefdfd9 100644 --- a/src/storage/v3/shard_worker.hpp +++ b/src/storage/v3/shard_worker.hpp @@ -92,6 +92,7 @@ class Queue { public: void Push(Message &&message) { { + MG_ASSERT(inner_.use_count() > 0); std::unique_lock lock(inner_->mu); inner_->queue.emplace_back(std::forward(message));