From 9963038dba18fb441dd15bca52de0c0b5e032985 Mon Sep 17 00:00:00 2001 From: abmdocrt Date: Fri, 16 Aug 2024 16:42:21 +0800 Subject: [PATCH] [Fix](core) Fix wal mgr heap use after free when stop doris (#33131) Problem: When the process stops, there is a heap use after free error with the WAL manager. Reason: During the startup process, if the storage engine does not initialize successfully and the main program directly returns 0, the WAL manager, which was created during initialization and started a thread to periodically check disk space, will encounter an issue. When the program exits and returns 0, local variables are destroyed first before the thread is properly terminated. If the thread attempts to access those local variables at this point, it leads to a heap use after free error. Solution: Ensure that the thread for periodically checking disk space is only started after the storage engine has been successfully initialized. ## Proposed changes Issue Number: close #xxx ## Further comments If this is a relatively large or complex change, kick off the discussion at [dev@doris.apache.org](mailto:dev@doris.apache.org) by explaining why you chose the solution you did and what alternatives you considered, etc... --- be/src/olap/wal/wal_manager.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/be/src/olap/wal/wal_manager.cpp b/be/src/olap/wal/wal_manager.cpp index 0df70919078d75..76795f9f0b69c9 100644 --- a/be/src/olap/wal/wal_manager.cpp +++ b/be/src/olap/wal/wal_manager.cpp @@ -476,6 +476,11 @@ Status WalManager::update_wal_dir_estimated_wal_bytes(const std::string& wal_dir Status WalManager::_update_wal_dir_info_thread() { while (!_stop.load()) { + if (!ExecEnv::ready()) { + LOG(INFO) << "Sleep 1s to wait for storage engine init."; + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); + continue; + } static_cast(_wal_dirs_info->update_all_wal_dir_limit()); static_cast(_wal_dirs_info->update_all_wal_dir_used()); LOG_EVERY_N(INFO, 100) << "Scheduled(every 10s) WAL info: " << get_wal_dirs_info_string();