Skip to content

fix: add timeout for DBus sync calls in DeviceInfo - #876

Open
add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/e9596b782571
Open

add-uos wants to merge 1 commit into
linuxdeepin:masterfrom
add-uos:agent/pms-bug-bot/e9596b782571

Conversation

@add-uos

@add-uos add-uos commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

fix: add timeout for DBus sync calls in DeviceInfo

  1. Root cause: DBusInterface::getInfo() uses synchronous DBus call
    without timeout, D-Bus default timeout (-1) blocks ~50s when
    service is missing, getAllInfo stacks ~30 calls causing severe lag
  2. Fix: call setTimeout(5000) on QDBusInterface in init() so all
    sync calls get 5s timeout, add waitForFinished(5000) in fallback
    path to eliminate additional no-timeout blocking risk
  3. Impact: single-file change in DBusInterface.cpp, no caller changes,
    normal service responses in milliseconds are unaffected

Influence:

  1. Test device info retrieval with DBus service running normally
  2. Test device info retrieval with DBus service missing, verify
    single call returns within ~5s instead of ~50s
  3. Verify getAllInfo overall loading time is significantly reduced
    when DBus service is unavailable

fix: 为设备信息 DBus 同步调用添加超时设置

  1. 根因:DBusInterface::getInfo() 同步 DBus 调用未设置超时,D-Bus
    默认超时(-1)在服务缺失时阻塞约 50 秒,getAllInfo 叠加约 30
    次调用导致严重卡顿
  2. 方案:在 init() 中对 QDBusInterface 调用 setTimeout(5000) 使所有
    同步调用 5 秒超时,fallback 路径 waitForFinished 添加 5000 参数
    消除额外的无超时阻塞风险
  3. 影响:仅修改 DBusInterface.cpp 一个文件,不涉及调用方代码,
    正常服务毫秒级响应不受影响

Influence:

  1. 测试 D-Bus 服务正常运行时设备信息获取功能
  2. 测试 D-Bus 服务缺失时单次调用约 5 秒内返回(而非 50 秒)
  3. 验证服务缺失场景下 getAllInfo 整体加载时间显著缩短

Summary by Sourcery

Bug Fixes:

  • Add five-second timeouts to synchronous DBus device-information requests so unavailable services no longer cause prolonged blocking.

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown

Sorry @add-uos, you've used your own review budget of 250,000 diff characters for the last 7 days.

You can request another review in 5 days and 4 hours by commenting @sourcery-ai review. Upgrade to get a review now.

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: add-uos

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

@sourcery-ai

sourcery-ai Bot commented Oct 23, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

The PR hardens DeviceInfo retrieval against unavailable DBus services by adding 5-second limits to the fallback process and shared QDBusInterface, without changing callers or the normal successful-response path.

Sequence diagram for DeviceInfo DBus timeout handling

sequenceDiagram
    participant Caller
    participant DBusInterface
    participant QDBusInterface
    participant FallbackProcess
    participant DBusService

    Caller->>DBusInterface: getInfo(key, info)
    DBusInterface->>QDBusInterface: sync DBus call
    QDBusInterface->>DBusService: getInfo
    alt service responds
        DBusService-->>QDBusInterface: device info
        QDBusInterface-->>DBusInterface: result
    else service unavailable
        QDBusInterface-->>DBusInterface: timeout after 5000 ms
        DBusInterface->>FallbackProcess: start gdbus getInfo
        FallbackProcess->>DBusService: getInfo
        FallbackProcess-->>DBusInterface: waitForFinished(5000)
    end
    DBusInterface-->>Caller: info or failure
Loading

File-Level Changes

Change Details Files
Apply a bounded timeout to both synchronous DBus access paths to prevent prolonged blocking when the service is unavailable.
  • Limit the fallback gdbus process wait to 5 seconds before reading output.
  • Configure the QDBusInterface with a 5-second timeout so synchronous interface calls inherit the bound.
deepin-devicemanager/src/GenerateDevice/DBusInterface.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

@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

总体评分: 93 分 (通过阈值: 70分)

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交为 DBus 同步调用添加超时机制,有效防止进程无限阻塞。两处改动语法正确、逻辑清晰,性能和安全方面均为正向改进。存在一处边界条件处理不足(waitForFinished 返回值未检查)和魔法数字硬编码问题,但整体风险较低,代码审查通过。

🔍 详细分析

1. 语法逻辑 ✅

评价: 存在边界条件处理不足 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['检查 waitForFinished(5000) 的返回值,超时时调用 process.kill() 终止进程并返回错误,避免读取不完整数据和进程残留']


2. 代码质量 ✅

评价: 代码结构清晰,存在魔法数字硬编码 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: ['将超时值提取为命名常量,如 static constexpr int DBUS_TIMEOUT_MS = 5000;,便于统一管理和后续调整']


3. 代码性能 ✅

评价: 性能良好,资源使用合理 ✅ 通过

潜在问题:
✅ 未发现明显问题

建议: []


4. 代码安全 🔒

评价: 存在0个安全漏洞 ✅ 通过

🔐 发现 0 个安全漏洞

安全漏洞详情:
✅ 未发现安全漏洞

建议: []


💡 改进建议代码示例

// 建议的改进方式:检查返回值并清理进程
// 在头文件或 cpp 文件顶部定义常量
static constexpr int DBUS_TIMEOUT_MS = 5000;

// getInfo() 函数中的改进
if (!process.waitForFinished(DBUS_TIMEOUT_MS)) {
    qCWarning(appLog) << "getInfo gdbus fallback timed out, killing process";
    process.kill();
    process.waitForFinished();
    return false;
}
QByteArray output = process.readAllStandardOutput();

// init() 函数中的改进
mp_Iface = new QDBusInterface(SERVICE_NAME, DEVICE_SERVICE_PATH, DEVICE_SERVICE_INTERFACE, QDBusConnection::systemBus());
mp_Iface->setTimeout(DBUS_TIMEOUT_MS);

本报告由 AI 代码审查工具自动生成

1. Root cause: DBusInterface::getInfo() uses synchronous DBus call
   without timeout, D-Bus default timeout (-1) blocks ~50s when
   service is missing, getAllInfo stacks ~30 calls causing severe lag
2. Fix: call setTimeout(5000) on QDBusInterface in init() so all
   sync calls get 5s timeout, add waitForFinished(5000) in fallback
   path to eliminate additional no-timeout blocking risk
3. Impact: single-file change in DBusInterface.cpp, no caller changes,
   normal service responses in milliseconds are unaffected

Influence:
1. Test device info retrieval with DBus service running normally
2. Test device info retrieval with DBus service missing, verify
   single call returns within ~5s instead of ~50s
3. Verify getAllInfo overall loading time is significantly reduced
   when DBus service is unavailable

fix: 为设备信息 DBus 同步调用添加超时设置

1. 根因:DBusInterface::getInfo() 同步 DBus 调用未设置超时,D-Bus
   默认超时(-1)在服务缺失时阻塞约 50 秒,getAllInfo 叠加约 30
   次调用导致严重卡顿
2. 方案:在 init() 中对 QDBusInterface 调用 setTimeout(5000) 使所有
   同步调用 5 秒超时,fallback 路径 waitForFinished 添加 5000 参数
   消除额外的无超时阻塞风险
3. 影响:仅修改 DBusInterface.cpp 一个文件,不涉及调用方代码,
   正常服务毫秒级响应不受影响

Influence:
1. 测试 D-Bus 服务正常运行时设备信息获取功能
2. 测试 D-Bus 服务缺失时单次调用约 5 秒内返回(而非 50 秒)
3. 验证服务缺失场景下 getAllInfo 整体加载时间显著缩短
@add-uos
add-uos force-pushed the agent/pms-bug-bot/e9596b782571 branch from 50db48f to 9299199 Compare October 27, 2026 03:43
@deepin-bot

deepin-bot Bot commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.0.75
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #956

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.

2 participants