Skip to content

Commit 8386f5d

Browse files
committed
fix: add ScopeGuard to wait async tasks before early return in Clean()
When GetUsedFiles() returns an error (e.g. index manifest not supported), Clean() would return immediately while thread pool tasks submitted via Via(executor_.get(), ...) were still running. These tasks capture 'this' and access members like fs_, causing use-after-free when the OrphanFilesCleanerImpl is destroyed shortly after. Add a ScopeGuard that calls CollectAll(file_statuses_futures) to ensure all submitted async tasks complete before the function returns, preventing the intermittent segmentation fault.
1 parent 7a2c831 commit 8386f5d

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

src/paimon/core/operation/orphan_files_cleaner_impl.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Result<std::set<std::string>> OrphanFilesCleanerImpl::Clean() {
9797
}
9898
PAIMON_ASSIGN_OR_RAISE(std::set<std::string> all_dirs, ListPaimonFileDirs());
9999
std::vector<std::future<std::vector<std::unique_ptr<FileStatus>>>> file_statuses_futures;
100+
ScopeGuard file_statuses_guard(
101+
[&file_statuses_futures]() { CollectAll(file_statuses_futures); });
100102
for (const auto& dir : all_dirs) {
101103
file_statuses_futures.push_back(
102104
Via(executor_.get(), [this, dir] { return TryBestListingDirs(dir); }));

0 commit comments

Comments
 (0)