From c4a8d5497d5a3a86bf5c4e4201a5d8693c0bf5fb Mon Sep 17 00:00:00 2001 From: zhannngchen <48427519+zhannngchen@users.noreply.github.com> Date: Tue, 6 Feb 2024 19:03:59 +0800 Subject: [PATCH] [fix](gc) process exception while iteratoring directory (#30850) --- be/src/io/fs/local_file_system.cpp | 33 ++++++++++++++++++------------ 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/be/src/io/fs/local_file_system.cpp b/be/src/io/fs/local_file_system.cpp index fc2008a677..cf28c7caa0 100644 --- a/be/src/io/fs/local_file_system.cpp +++ b/be/src/io/fs/local_file_system.cpp @@ -203,23 +203,30 @@ Status LocalFileSystem::list_impl(const Path& dir, bool only_file, std::vectorpush_back(std::move(file_info)); } - files->push_back(std::move(file_info)); + } catch (const std::filesystem::filesystem_error& e) { + // although `directory_iterator(dir, ec)` does not throw an exception, + // it may throw an exception during iterator++, so we need to catch the exception here + return localfs_error(e.code(), fmt::format("failed to list {}, error message: {}", + dir.native(), e.what())); } if (ec) { return localfs_error(ec, fmt::format("failed to list {}", dir.native()));