From 9299199c222136d228b2758c034ebdedb33e4338 Mon Sep 17 00:00:00 2001 From: zhanghongyuan Date: Fri, 23 Oct 2026 08:36:37 +0800 Subject: [PATCH] fix: add timeout for DBus sync calls in DeviceInfo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 整体加载时间显著缩短 --- deepin-devicemanager/src/GenerateDevice/DBusInterface.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/deepin-devicemanager/src/GenerateDevice/DBusInterface.cpp b/deepin-devicemanager/src/GenerateDevice/DBusInterface.cpp index 21ebd84f8..253aa0c78 100644 --- a/deepin-devicemanager/src/GenerateDevice/DBusInterface.cpp +++ b/deepin-devicemanager/src/GenerateDevice/DBusInterface.cpp @@ -48,7 +48,7 @@ bool DBusInterface::getInfo(const QString &key, QString &info) << "--object-path" << "/org/deepin/DeviceInfo" << "--method" << "org.deepin.DeviceInfo.getInfo" << "hwinfo"); - process.waitForFinished(); + process.waitForFinished(5000); QByteArray output = process.readAllStandardOutput(); QString outputStr = QString::fromLocal8Bit(output); qCInfo(appLog) << "getInfo gdbus out:" << outputStr.left(10); //debug detect service work is really unstable @@ -75,5 +75,6 @@ void DBusInterface::init() // 2. create interface mp_Iface = new QDBusInterface(SERVICE_NAME, DEVICE_SERVICE_PATH, DEVICE_SERVICE_INTERFACE, QDBusConnection::systemBus()); + mp_Iface->setTimeout(5000); qCDebug(appLog) << "DBusInterface::init end, iface created:" << (mp_Iface != nullptr); }