Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
deepin-anything (7.0.33) unstable; urgency=medium

* feat: Improve daemon stability and resource management

-- wangrong <wangrong@uniontech.com> Fri, 28 Nov 2025 17:02:59 +0800

deepin-anything (7.0.32) unstable; urgency=medium

* fix: Fix deepin-anything-daemon coredump
Expand Down
6 changes: 4 additions & 2 deletions src/daemon/deepin-anything-daemon.service
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ After=udisks2.service
ExecStart=/usr/libexec/deepin-anything-daemon
Restart=on-failure
RestartSec=30
MemoryHigh=4G
MemoryMax=5G
StartLimitIntervalSec=3600 # The time window is 3600 seconds (60 minutes)
StartLimitBurst=2 # A maximum of 2 starts are allowed within this window.
MemoryHigh=2G
MemoryMax=3G

[Install]
WantedBy=default.target
40 changes: 24 additions & 16 deletions src/daemon/src/core/base_event_handler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,10 @@
pool_.wait_for_tasks();
if (!jobs_.empty()) {
// Eat all jobs
for (auto&& job : jobs_) {
for (auto &&job : jobs_) {
eat_job(std::move(job));
}
jobs_.clear();
}
}

Expand Down Expand Up @@ -350,25 +351,32 @@
spdlog::info("Scanning directory {}", dir_path);

std::error_code ec;
std::string path;

Check warning on line 354 in src/daemon/src/core/base_event_handler.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The scope of the variable 'path' can be reduced. Warning: Be careful when fixing this message, especially when there are inner loops. Here is an example where cppcheck will write that the scope for 'i' can be reduced:\012void f(int x)\012{\012 int i = 0;\012 if (x) {\012 // it's safe to move 'int i = 0;' here\012 for (int n = 0; n < 10; ++n) {\012 // it is possible but not safe to move 'int i = 0;' here\012 do_something(&i);\012 }\012 }\012}\012When you see this message it is always safe to reduce the variable scope 1 level.
// By default, symlinks are not followed
std::filesystem::recursive_directory_iterator dirpos{ dir_path, std::filesystem::directory_options::skip_permission_denied };
for (auto it = begin(dirpos); it != end(dirpos); ++it) {
path = std::move(it->path().string());
if (is_path_in_blacklist(path, config_->blacklist_paths) ||
!std::filesystem::exists(it->path(), ec)) {
it.disable_recursion_pending();
continue;
}

if (!handler(path)) {
return false;
}
try {
// By default, symlinks are not followed
std::filesystem::recursive_directory_iterator dirpos{ dir_path, std::filesystem::directory_options::skip_permission_denied };
for (auto it = begin(dirpos); it != end(dirpos); ++it) {
path = std::move(it->path().string());
if (is_path_in_blacklist(path, config_->blacklist_paths) ||
!std::filesystem::exists(it->path(), ec)) {
it.disable_recursion_pending();
continue;
}

if (stop_scan_directory_) {
spdlog::info("Scanning interrupted");
return true;
if (!handler(path)) {
spdlog::error("Failed to handle path: {}", path);
return false;
}

if (stop_scan_directory_) {
spdlog::info("Scanning interrupted");
return true;
}
}
} catch (std::filesystem::filesystem_error const& e) {
spdlog::error("Failed to scan directory: {}, {}, {}, {}",
e.what(), e.path1().string(), e.path2().string(), e.code().value());
}

spdlog::info("Scanning directory {} completed", dir_path);
Expand Down
9 changes: 5 additions & 4 deletions src/daemon/src/core/file_index_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,10 @@ file_index_manager::file_index_manager(const std::string& persistent_index_dir,
}
} catch (const LuceneException& e) {
spdlog::warn("The index is corrupted: {}", volatile_index_directory_);
std::error_code ec;
if (writer_) writer_->close();
if (reader_) reader_->close();
std::filesystem::remove_all(volatile_index_directory_);
std::filesystem::remove_all(volatile_index_directory_, ec);
Comment on lines +187 to +190
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Swallowing errors from remove_all can leave a corrupted index without any signal.

Switching from the throwing remove_all to the std::error_code overload makes failures silent. Right now ec is ignored, so callers proceed as if the directory was removed even when it wasn’t, which can leave a bad index in place and cause confusing follow‑on behavior.

At minimum, check and log failures, e.g.:

std::filesystem::remove_all(volatile_index_directory_, ec);
if (ec) {
    spdlog::error("Failed to remove corrupted index {}: {} ({})",
                  volatile_index_directory_, ec.message(), ec.value());
}

The same pattern should be applied to the other remove_all(..., ec) calls in check_index_version() so cleanup issues are visible during diagnosis.


writer_ = newLucene<IndexWriter>(dir,
newLucene<ChineseAnalyzer>(),
Expand Down Expand Up @@ -575,7 +576,7 @@ void file_index_manager::check_index_version() {
// 检查是否是无效索引
if (std::filesystem::exists(volatile_index_directory_ + "/invalid_index", ec)) {
spdlog::warn("The index is invalid: {}, remove it", volatile_index_directory_);
std::filesystem::remove_all(volatile_index_directory_);
std::filesystem::remove_all(volatile_index_directory_, ec);
return;
}

Expand All @@ -587,7 +588,7 @@ void file_index_manager::check_index_version() {
spdlog::warn("The index is corrupted: {}", volatile_index_directory_);
if (reader) reader->close();
spdlog::warn("Removing the corrupted index...");
std::filesystem::remove_all(volatile_index_directory_);
std::filesystem::remove_all(volatile_index_directory_, ec);
return;
}

Expand All @@ -610,7 +611,7 @@ void file_index_manager::check_index_version() {
} else {
spdlog::warn("The index version is mismatched: {}", volatile_index_directory_);
spdlog::warn("Removing the incompatible index...");
std::filesystem::remove_all(volatile_index_directory_);
std::filesystem::remove_all(volatile_index_directory_, ec);
}
}

Expand Down