From c9b0fc10640bade836af587be8a977e76bcbd8bb Mon Sep 17 00:00:00 2001 From: jsteemann Date: Tue, 23 Apr 2024 13:19:58 +0200 Subject: [PATCH] fix ASan errors in test should fix the following test error with sanitizers enabled: [FAILED] tests/js/client/shell/shell-verify-sst-noncluster.js "testVerify" failed: Error: at assertion #6: { "pid" : 896, "status" : "TERMINATED", "exit" : 1 }: (1) is not equal to (0) (Error at verifySsts (tests/js/client/shell/shell-verify-sst-noncluster.js:106:9) at tests/js/client/shell/shell-verify-sst-noncluster.js:116:11 at Object.testVerify (tests/js/client/shell/shell-verify-sst-noncluster.js:111:12) .... at Object.shellClient [as shell_client] (/root/project/js/client/modules/@arangodb/testsuites/aql.js:209:79) - test failed --- arangod/RocksDBEngine/RocksDBEngine.cpp | 6 ++++-- arangod/Scheduler/SupervisedScheduler.cpp | 11 ++++++++++- arangod/Transaction/ManagerFeature.cpp | 9 +++++++-- lib/Logger/LogThread.cpp | 6 ++++++ 4 files changed, 27 insertions(+), 5 deletions(-) diff --git a/arangod/RocksDBEngine/RocksDBEngine.cpp b/arangod/RocksDBEngine/RocksDBEngine.cpp index 2c362f6695f9..34333e89b72c 100644 --- a/arangod/RocksDBEngine/RocksDBEngine.cpp +++ b/arangod/RocksDBEngine/RocksDBEngine.cpp @@ -888,8 +888,10 @@ void RocksDBEngine::verifySstFiles(rocksdb::Options const& options) const { << "verification of RocksDB .sst files in path '" << _path << "' completed successfully"; Logger::flush(); - - exit(EXIT_SUCCESS); + // exit with status code = 0, without leaking + int exitCode = static_cast(TRI_ERROR_NO_ERROR); + TRI_EXIT_FUNCTION(exitCode, nullptr); + exit(exitCode); } namespace { diff --git a/arangod/Scheduler/SupervisedScheduler.cpp b/arangod/Scheduler/SupervisedScheduler.cpp index 4cd813c30493..bc8f491b110a 100644 --- a/arangod/Scheduler/SupervisedScheduler.cpp +++ b/arangod/Scheduler/SupervisedScheduler.cpp @@ -267,7 +267,16 @@ SupervisedScheduler::SupervisedScheduler( TRI_ASSERT(fifo3Size > 0); } -SupervisedScheduler::~SupervisedScheduler() = default; +SupervisedScheduler::~SupervisedScheduler() { + // make sure we are freeing all items from all queues here if we + // are in an uncontrolled shutdown + for (size_t i = 0; i < NumberOfQueues; ++i) { + WorkItemBase* res = nullptr; + while (_queues[i].queue.pop(res)) { + delete res; + } + } +} void SupervisedScheduler::trackQueueItemSize(std::int64_t x) noexcept { _schedulerQueueMemory += x; diff --git a/arangod/Transaction/ManagerFeature.cpp b/arangod/Transaction/ManagerFeature.cpp index ce742fed0c46..650398db19c3 100644 --- a/arangod/Transaction/ManagerFeature.cpp +++ b/arangod/Transaction/ManagerFeature.cpp @@ -70,7 +70,9 @@ ManagerFeature::ManagerFeature(Server& server) return; } - MANAGER->garbageCollect(/*abortAll*/ false); + if (MANAGER != nullptr) { + MANAGER->garbageCollect(/*abortAll*/ false); + } if (!this->server().isStopping()) { queueGarbageCollection(); @@ -78,7 +80,10 @@ ManagerFeature::ManagerFeature(Server& server) }; } -ManagerFeature::~ManagerFeature() = default; +ManagerFeature::~ManagerFeature() { + std::lock_guard guard(_workItemMutex); + _workItem.reset(); +} void ManagerFeature::collectOptions(std::shared_ptr options) { options->addSection("transaction", "transactions"); diff --git a/lib/Logger/LogThread.cpp b/lib/Logger/LogThread.cpp index fbaa125ffd64..38c673c6a903 100644 --- a/lib/Logger/LogThread.cpp +++ b/lib/Logger/LogThread.cpp @@ -37,6 +37,12 @@ LogThread::LogThread(application_features::ApplicationServer& server, LogThread::~LogThread() { Logger::_active = false; + // make sure there are no memory leaks on uncontrolled shutdown + MessageEnvelope env{nullptr, nullptr}; + while (_messages.pop(env)) { + delete env.msg; + } + shutdown(); }