diff --git a/src/cpp/server/server.cc b/src/cpp/server/server.cc index e69032a657d..87296805652 100644 --- a/src/cpp/server/server.cc +++ b/src/cpp/server/server.cc @@ -179,12 +179,12 @@ Server::Server(ThreadPoolInterface* thread_pool, bool thread_pool_owned) thread_pool_owned_(thread_pool_owned) {} Server::~Server() { - std::unique_lock lock(mu_); - if (started_ && !shutdown_) { - lock.unlock(); - Shutdown(); - } else { - lock.unlock(); + { + std::unique_lock lock(mu_); + if (started_ && !shutdown_) { + lock.unlock(); + Shutdown(); + } } grpc_server_destroy(server_); if (thread_pool_owned_) {