Skip to content

fix: Set timeout for device info loading to prevent infinite waiting#531

Merged
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
add-uos:develop/eagle
Sep 5, 2025
Merged

fix: Set timeout for device info loading to prevent infinite waiting#531
deepin-bot[bot] merged 1 commit intolinuxdeepin:develop/eaglefrom
add-uos:develop/eagle

Conversation

@add-uos
Copy link
Contributor

@add-uos add-uos commented Sep 5, 2025

  • Change waitForDone(-1) to waitForDone(60000) in MainJob::updateAllDevice()
  • Add 60-second timeout to prevent device manager from hanging during device info loading
  • Improve application responsiveness and user experience

Log: Set timeout for device info loading to prevent infinite waiting
Bug: https://pms.uniontech.com/bug-view-331983.html
Change-Id: Iab0310719df4cfa7e13176975ee0db59572d88ce

Summary by Sourcery

Add a 60-second timeout to m_pool->waitForDone in MainJob::updateAllDevice to prevent the device manager from hanging indefinitely when loading device info.

Bug Fixes:

  • Prevent infinite waiting in MainJob::updateAllDevice by setting a 60-second timeout for m_pool->waitForDone.

Enhancements:

  • Improve application responsiveness and user experience by avoiding indefinite hangs during device info loading.

- Change waitForDone(-1) to waitForDone(60000) in MainJob::updateAllDevice()
- Add 60-second timeout to prevent device manager from hanging during device info loading
- Improve application responsiveness and user experience

Log: Set timeout for device info loading to prevent infinite waiting
Bug: https://pms.uniontech.com/bug-view-331983.html
Change-Id: Iab0310719df4cfa7e13176975ee0db59572d88ce
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码的修改是将waitForDone的参数从-1改为60000,我来分析一下这个修改的影响和潜在问题:

  1. 语法和逻辑:
  • 语法上没有问题,waitForDone接受一个超时时间参数(毫秒)
  • 逻辑上是合理的,设置了一个明确的超时时间,避免了无限等待
  1. 代码质量:
  • 原代码使用-1表示无限等待,这是一种常见的做法,但在某些情况下可能导致程序长时间卡住
  • 修改后的代码设置了60秒(60000毫秒)的超时时间,这是一个合理的折中值
  1. 代码性能:
  • 原代码的无限等待可能导致线程长时间阻塞,影响系统响应性
  • 修改后的代码限制了最大等待时间,提高了系统的响应性
  1. 代码安全:
  • 增加了超时机制,防止了可能的死锁情况导致程序永久卡住
  • 60秒的超时时间对于设备信息更新操作来说通常是足够的

改进建议:

  1. 建议将60000这个魔数定义为常量或配置项,提高代码可维护性
  2. 可以考虑添加超时后的错误处理逻辑,比如记录日志或通知用户
  3. 如果60秒对于某些设备来说可能不够,可以考虑根据设备类型或数量动态调整超时时间

修改后的代码如下(建议):

void MainJob::updateAllDevice()
{
    PERF_PRINT_START("POINT-01");
    
    const int DEVICE_INFO_UPDATE_TIMEOUT = 60000; // 定义超时常量
    
    if (m_firstUpdate)
        m_pool->loadDeviceInfo();
    else
        m_pool->updateDeviceInfo();
    
    bool success = m_pool->waitForDone(DEVICE_INFO_UPDATE_TIMEOUT);
    if (!success) {
        // 添加超时处理逻辑
        qWarning() << "Device info update timed out after" << DEVICE_INFO_UPDATE_TIMEOUT << "ms";
    }
    
    PERF_PRINT_END("POINT-01");
    m_firstUpdate = false;
}

这样的修改不仅提高了代码的可读性和可维护性,还增加了错误处理机制,使代码更加健壮。

@sourcery-ai
Copy link

sourcery-ai bot commented Sep 5, 2025

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Replace the indefinite wait on device info loading with a 60-second timeout in MainJob::updateAllDevice to avoid hangs and improve responsiveness.

Sequence diagram for device info loading with timeout

sequenceDiagram
    participant MainJob
    participant DevicePool
    MainJob->>DevicePool: loadDeviceInfo() or updateDeviceInfo()
    MainJob->>DevicePool: waitForDone(60000)
    DevicePool-->>MainJob: Done or Timeout after 60s
Loading

File-Level Changes

Change Details Files
Enforce a timeout on the device info loading wait call
  • Changed waitForDone argument from -1 (infinite) to 60000 (60 seconds)
  • Added 60-second timeout to prevent device manager from hanging
deepin-devicemanager-server/deepin-deviceinfo/src/mainjob.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 - here's some feedback:

  • Consider extracting the 60000ms timeout into a named constant or configuration setting instead of using a hardcoded magic number.
  • Add explicit handling or logging for when waitForDone times out so that failures in device info loading are surfaced.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Consider extracting the 60000ms timeout into a named constant or configuration setting instead of using a hardcoded magic number.
- Add explicit handling or logging for when waitForDone times out so that failures in device info loading are surfaced.

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

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos, GongHeng2017, max-lvs

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

@add-uos
Copy link
Contributor Author

add-uos commented Sep 5, 2025

/merge

@deepin-bot deepin-bot bot merged commit 00f82e6 into linuxdeepin:develop/eagle Sep 5, 2025
17 checks passed
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.

4 participants