This is an automated email from the ASF dual-hosted git repository. alexey pushed a commit to branch branch-1.18.x in repository https://gitbox.apache.org/repos/asf/kudu.git
commit a858c654dc55bb51e71c6668e781f03f06195a67 Author: Alexey Serbin <[email protected]> AuthorDate: Sun Aug 10 12:03:58 2025 -0700 KUDU-2439 properly update Messenger instance counter This is a follow-up to d1413014255df62a6e38550552a8596644aa0033. Change-Id: I61b96e7157e1efd930092cc9e5bfde33bf523098 Reviewed-on: http://gerrit.cloudera.org:8080/23277 Tested-by: Alexey Serbin <[email protected]> Reviewed-by: Zoltan Martonka <[email protected]> Reviewed-by: Abhishek Chennaka <[email protected]> (cherry picked from commit 8e873eb37b157a0cf7cb97cc7690367de9707107) Reviewed-on: http://gerrit.cloudera.org:8080/23283 Reviewed-by: Alexey Serbin <[email protected]> --- src/kudu/rpc/messenger.cc | 8 ++++++++ src/kudu/util/before_and_after_main.h | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/kudu/rpc/messenger.cc b/src/kudu/rpc/messenger.cc index fbff6774b..85222518b 100644 --- a/src/kudu/rpc/messenger.cc +++ b/src/kudu/rpc/messenger.cc @@ -416,6 +416,14 @@ uint32_t Messenger::GetInstanceCount() { Messenger::~Messenger() { CHECK_EQ(state_, kClosing) << "Should have already shut down"; STLDeleteElements(&reactors_); + + // KUDU(2439): kInstanceCount_'s zeroing is used as a criterion for the proper + // timing of OPENSSL_clean() call; so, it's crucial to make sure + // the sub-objects that call the OpenSSL API in their destructor + // are already destroyed when the instance counter reaches zero + jwt_verifier_.reset(); + token_verifier_.reset(); + tls_context_.reset(); kInstanceCount_.fetch_sub(1, std::memory_order_release); } diff --git a/src/kudu/util/before_and_after_main.h b/src/kudu/util/before_and_after_main.h index cf77c428b..85806b47f 100644 --- a/src/kudu/util/before_and_after_main.h +++ b/src/kudu/util/before_and_after_main.h @@ -89,14 +89,18 @@ static void module_fini_openssl() { // majority of the kudu CLI's use cases, it's better to incur an extra second // of latency compared with a crash and inability to tell whether the tool // succeeded or not by analyzing its exit code. - if (const auto mc = kudu::rpc::Messenger::GetInstanceCount(); mc != 0) { + if (auto mc = kudu::rpc::Messenger::GetInstanceCount(); mc != 0) { RAW_VLOG(2, "waiting for %d Messengers to shut down", mc); const auto deadline = kudu::MonoTime::Now() + kudu::MonoDelta::FromSeconds(1); - while (kudu::MonoTime::Now() < deadline) { + do { SleepFor(kudu::MonoDelta::FromMilliseconds(50)); - if (kudu::rpc::Messenger::GetInstanceCount() == 0) { + mc = kudu::rpc::Messenger::GetInstanceCount(); + if (mc == 0) { break; } + } while (kudu::MonoTime::Now() < deadline); + if (mc != 0) { + RAW_LOG(WARNING, "possible race with %d thread(s) on OpenSSL cleanup", mc); } } #endif // #if !defined(KUDU_TEST_MAIN) ... @@ -104,7 +108,7 @@ static void module_fini_openssl() { // Call OPENSSL_cleanup() to release resources and clean up the global state // of the library: it's applicable to OpenSSL 1.1.1 and newer versions. // At this point, tcmalloc must still be operational. - RAW_VLOG(2, "cleaning up OpenSSL runtime"); + RAW_VLOG(2, "cleaning up OpenSSL"); kudu::security::FinalizeOpenSSL(); }
