Skip to content

Conversation

@wangrong1069
Copy link
Contributor

@wangrong1069 wangrong1069 commented Nov 11, 2025

When disk space is exhausted, deepin-anything-daemon will throw an exception upon startup due to failure to create the index directory.

Summary by Sourcery

Bug Fixes:

  • Handle file_index_manager initialization failures by exiting with a defined quit code instead of throwing an exception to prevent coredumps on low disk space

When disk space is exhausted, deepin-anything-daemon will throw an
exception upon startup due to failure to create the index directory.
@github-actions
Copy link

TAG Bot

TAG: 7.0.32
EXISTED: no
DISTRIBUTION: unstable

@sourcery-ai
Copy link

sourcery-ai bot commented Nov 11, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replace throwing of std::runtime_error with a controlled process exit on file index initialization failure to prevent coredumps when disk space is exhausted

Sequence diagram for file_index_manager initialization failure handling

sequenceDiagram
participant D["deepin-anything-daemon"]
participant F["file_index_manager"]
participant L["LuceneException"]
D->>F: Initialize file_index_manager
F->>L: Attempt to create index directory
L-->>F: Throws LuceneException (e.g., disk full)
F->>D: Log critical error
F->>D: Exit process with APP_QUIT_CODE
Loading

Class diagram for updated file_index_manager error handling

classDiagram
class file_index_manager {
    +file_index_manager(persistent_index_dir, ...)
    -On LuceneException: exit(APP_QUIT_CODE)
}
class LuceneException {
    +getError()
}
file_index_manager --> LuceneException: handles exception
Loading

File-Level Changes

Change Details Files
Handle index manager initialization failure by exiting
  • Catch LuceneException and construct error message
  • Log critical error via spdlog
  • Invoke exit(APP_QUIT_CODE) instead of throwing std::runtime_error
src/daemon/src/core/file_index_manager.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

deepin pr auto review

我来对这段代码变更进行审查:

  1. debian/changelog:
  • 版本号从 7.0.31 更新到 7.0.32
  • 修复了 deepin-anything-daemon 的 coredump 问题
  • 维护者信息和日期格式规范
  • 变更记录清晰,符合 Debian 包管理规范
  1. debian/rules:
  • 添加了 DEB_LDFLAGS_APPEND = -Wl,-z,now
  • 这是一个安全相关的改进,启用 BIND_NOW 标志
  • 这会在程序启动时就解析所有动态符号,而不是延迟加载
  • 可以防止某些利用延迟绑定的攻击
  • 建议保持这个改动
  1. src/daemon/src/core/file_index_manager.cpp:
  • 将异常处理从 throw std::runtime_error 改为 exit(APP_QUIT_CODE)
  • 这个改动需要谨慎考虑:

优点:

  • 确保程序在严重错误时立即退出
  • 避免异常传播可能导致的不确定行为

潜在问题:

  • 直接 exit() 会导致程序突然终止,可能无法正确清理资源
  • 没有给调用者处理错误的机会
  • 如果这个对象是其他对象的一部分,可能导致部分初始化的对象

改进建议:

  1. 建议改为:
try {
    // 初始化代码
} catch (const LuceneException& e) {
    std::string error_msg = "Failed to initialize file_index_manager: " + StringUtils::toUTF8(e.getError());
    spdlog::critical(error_msg);
    
    // 清理已分配的资源
    cleanup_resources();
    
    exit(APP_QUIT_CODE);
}
  1. 或者考虑使用 RAII 和智能指针确保资源自动清理

  2. 如果可能,最好让调用者处理这个错误,而不是直接退出程序:

try {
    // 初始化代码
} catch (const LuceneException& e) {
    std::string error_msg = "Failed to initialize file_index_manager: " + StringUtils::toUTF8(e.getError());
    spdlog::critical(error_msg);
    throw InitializationException(error_msg);
}

总体来说:

  • debian 相关的改动是好的
  • 安全加固措施是合适的
  • 异常处理的改动需要更多考虑,建议采用更优雅的错误处理方式
  • 如果必须使用 exit(),确保所有资源都能正确清理

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wangrong1069

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@wangrong1069
Copy link
Contributor Author

/merge

@deepin-bot deepin-bot bot merged commit e6a7b02 into linuxdeepin:develop/snipe Nov 12, 2025
19 checks passed
@wangrong1069 wangrong1069 deleted the pr1111 branch November 12, 2025 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants