Skip to content

fix: resolve DBUS deadlock in application tray#430

Open
18202781743 wants to merge 1 commit intolinuxdeepin:masterfrom
18202781743:master
Open

fix: resolve DBUS deadlock in application tray#430
18202781743 wants to merge 1 commit intolinuxdeepin:masterfrom
18202781743:master

Conversation

@18202781743
Copy link
Contributor

@18202781743 18202781743 commented Feb 12, 2026

  1. Changed from Qt's DBus interface generation to DTK's asynchronous
    DBus interface generation for StatusNotifierItem
  2. Added DTK Tools dependency to CMakeLists.txt for
    dtk_add_dbus_interfaces
  3. Modified DBus interface generation to use dtk_add_dbus_interfaces for
    org.kde.StatusNotifierItem.xml
  4. Updated include directories to include the local api directory
  5. Removed forward declaration of StatusNotifierItem class since it's
    now generated by DTK
  6. Added namespace usage for org::kde in sniprotocolhandler.h

The issue was that Qt's synchronous DBus property calls could cause
deadlocks in the application tray. By switching to DTK's asynchronous
DBus interface generation, property access becomes non-blocking,
preventing the deadlock situation. This change specifically targets the
StatusNotifierItem interface which was causing the deadlock.

Log: Fixed application tray DBus deadlock issue

Influence:

  1. Test application tray functionality with various system tray
    applications
  2. Verify tray icons load correctly without hanging
  3. Test DBus communication with StatusNotifierItem services
  4. Monitor system responsiveness when multiple tray applications are
    running
  5. Test tray menu interactions and property updates
  6. Verify no regression in tray icon display or functionality

fix: 解决应用托盘DBus死锁问题

  1. 将StatusNotifierItem的DBus接口生成从Qt改为DTK的异步DBus接口生成
  2. 在CMakeLists.txt中添加DTK Tools依赖以使用dtk_add_dbus_interfaces
  3. 修改DBus接口生成,对org.kde.StatusNotifierItem.xml使用
    dtk_add_dbus_interfaces
  4. 更新包含目录以包含本地api目录
  5. 移除StatusNotifierItem类的前向声明,因为现在由DTK生成
  6. 在sniprotocolhandler.h中添加org::kde命名空间使用

问题在于Qt的同步DBus属性调用可能导致应用托盘死锁。通过切换到DTK的异步
DBus接口生成,属性访问变为非阻塞操作,防止了死锁情况。此更改专门针对导致
死锁的StatusNotifierItem接口。

Log: 修复应用托盘DBus死锁问题

Influence:

  1. 测试应用托盘功能与各种系统托盘应用程序
  2. 验证托盘图标正确加载且无卡顿
  3. 测试与StatusNotifierItem服务的DBus通信
  4. 监控运行多个托盘应用程序时的系统响应性
  5. 测试托盘菜单交互和属性更新
  6. 验证托盘图标显示和功能无回归问题

Summary by Sourcery

Switch StatusNotifierItem DBus interface generation to DTK’s asynchronous interfaces to resolve application tray DBus deadlocks.

Bug Fixes:

  • Prevent application tray deadlocks caused by synchronous DBus property access on the StatusNotifierItem interface.

Enhancements:

  • Update StatusNotifierItem DBus interface usage to rely on DTK-generated types and namespaces.
  • Refresh SPDX copyright headers to cover 2024–2026 across modified plugin files.

Build:

  • Add DTK Tools as a build dependency and use dtk_add_dbus_interfaces for org.kde.StatusNotifierItem.xml.
  • Extend plugin include directories to reference the local application-tray API directory.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743

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
Copy link

sourcery-ai bot commented Feb 12, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Switches StatusNotifierItem DBus interface generation from Qt’s synchronous qt_add_dbus_interfaces to DTK’s asynchronous dtk_add_dbus_interfaces to avoid DBus deadlocks in the application tray, adds the required DTK Tools dependency and include path, and cleans up declarations/namespacing for the generated types.

Sequence diagram for asynchronous StatusNotifierItem DBus property access

sequenceDiagram
    participant DockApplicationTrayPlugin
    participant SniTrayProtocolHandler
    participant StatusNotifierItemAsyncProxy
    participant DBusBus
    participant StatusNotifierItemService

    DockApplicationTrayPlugin->>SniTrayProtocolHandler: requestStatusNotifierProperties
    SniTrayProtocolHandler->>StatusNotifierItemAsyncProxy: getPropertiesAsync
    StatusNotifierItemAsyncProxy->>DBusBus: org.kde.StatusNotifierItem.GetAll
    DBusBus->>StatusNotifierItemService: GetAll
    StatusNotifierItemService-->>DBusBus: properties
    DBusBus-->>StatusNotifierItemAsyncProxy: properties
    StatusNotifierItemAsyncProxy-->>SniTrayProtocolHandler: propertiesCallback
    SniTrayProtocolHandler-->>DockApplicationTrayPlugin: updateTrayIconState
Loading

File-Level Changes

Change Details Files
Use DTK’s asynchronous DBus interface generation for StatusNotifierItem instead of Qt’s synchronous generation.
  • Remove org.kde.StatusNotifierItem.xml from qt_add_dbus_interfaces invocation so it is no longer generated via Qt’s DBus tooling.
  • Add a dtk_add_dbus_interfaces call that generates the DBus proxy for org.kde.StatusNotifierItem.xml via DTK, enabling asynchronous property access.
plugins/application-tray/CMakeLists.txt
Ensure build configuration supports DTK DBus interface generation and the generated headers are discoverable.
  • Extend Dtk find_package to require the Tools component, which provides dtk_add_dbus_interfaces.
  • Add the plugins/application-tray/api directory to the target’s public include directories so generated StatusNotifierItem headers can be included.
  • Update SPDX copyright years in touched CMake file.
plugins/application-tray/CMakeLists.txt
Align C++ headers with the new generated StatusNotifierItem type and its namespace.
  • Remove the manual forward declaration of StatusNotifierItem, since the class is now provided by the DTK‑generated header.
  • Introduce using namespace org::kde; inside the tray namespace so code using StatusNotifierItem (and related types) can reference them without full qualification.
  • Update SPDX copyright years in the affected headers.
plugins/application-tray/ddeindicatortrayprotocol.h
plugins/application-tray/sniprotocolhandler.h

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 - I've found 1 issue, and left some high level feedback:

  • Avoid using namespace org::kde; in sniprotocolhandler.h, as this is a header and will leak the namespace into all includers; prefer qualifying the specific types or introducing a using-alias for the required classes only.
  • In the CMakeLists, consider using ${CMAKE_CURRENT_SOURCE_DIR}/api/ instead of ${CMAKE_SOURCE_DIR}/plugins/application-tray/api/ for the include directory so the target remains more self-contained and easier to reuse or move.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Avoid `using namespace org::kde;` in `sniprotocolhandler.h`, as this is a header and will leak the namespace into all includers; prefer qualifying the specific types or introducing a using-alias for the required classes only.
- In the CMakeLists, consider using `${CMAKE_CURRENT_SOURCE_DIR}/api/` instead of `${CMAKE_SOURCE_DIR}/plugins/application-tray/api/` for the include directory so the target remains more self-contained and easier to reuse or move.

## Individual Comments

### Comment 1
<location> `plugins/application-tray/sniprotocolhandler.h:20-21` </location>
<code_context>
 class DBusMenuImporter;
-class StatusNotifierItem;

 namespace tray {
 class DDEindicatorProtocolHandler;
</code_context>

<issue_to_address>
**issue:** Avoid `using namespace` in a public header to prevent polluting includers’ namespaces.

Putting `using namespace org::kde;` in a header injects all of `org::kde` into every includer’s global namespace, risking symbol collisions and confusing name lookup. Prefer fully qualifying `org::kde` types here or introducing a narrow alias (e.g. `namespace kde = org::kde;`) and using that explicitly, and keep any broad `using` directives in the .cpp file instead.
</issue_to_address>

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.

1. Changed from Qt's DBus interface generation to DTK's asynchronous
DBus interface generation for StatusNotifierItem
2. Added DTK Tools dependency to CMakeLists.txt for
dtk_add_dbus_interfaces
3. Modified DBus interface generation to use dtk_add_dbus_interfaces for
org.kde.StatusNotifierItem.xml
4. Updated include directories to include the local api directory
5. Removed forward declaration of StatusNotifierItem class since it's
now generated by DTK
6. Added namespace usage for org::kde in sniprotocolhandler.h

The issue was that Qt's synchronous DBus property calls could cause
deadlocks in the application tray. By switching to DTK's asynchronous
DBus interface generation, property access becomes non-blocking,
preventing the deadlock situation. This change specifically targets the
StatusNotifierItem interface which was causing the deadlock.

Log: Fixed application tray DBus deadlock issue

Influence:
1. Test application tray functionality with various system tray
applications
2. Verify tray icons load correctly without hanging
3. Test DBus communication with StatusNotifierItem services
4. Monitor system responsiveness when multiple tray applications are
running
5. Test tray menu interactions and property updates
6. Verify no regression in tray icon display or functionality

fix: 解决应用托盘DBus死锁问题

1. 将StatusNotifierItem的DBus接口生成从Qt改为DTK的异步DBus接口生成
2. 在CMakeLists.txt中添加DTK Tools依赖以使用dtk_add_dbus_interfaces
3. 修改DBus接口生成,对org.kde.StatusNotifierItem.xml使用
dtk_add_dbus_interfaces
4. 更新包含目录以包含本地api目录
5. 移除StatusNotifierItem类的前向声明,因为现在由DTK生成
6. 在sniprotocolhandler.h中添加org::kde命名空间使用

问题在于Qt的同步DBus属性调用可能导致应用托盘死锁。通过切换到DTK的异步
DBus接口生成,属性访问变为非阻塞操作,防止了死锁情况。此更改专门针对导致
死锁的StatusNotifierItem接口。

Log: 修复应用托盘DBus死锁问题

Influence:
1. 测试应用托盘功能与各种系统托盘应用程序
2. 验证托盘图标正确加载且无卡顿
3. 测试与StatusNotifierItem服务的DBus通信
4. 监控运行多个托盘应用程序时的系统响应性
5. 测试托盘菜单交互和属性更新
6. 验证托盘图标显示和功能无回归问题
@deepin-ci-robot
Copy link

deepin pr auto review

这份代码变更主要涉及 application-tray 插件的构建配置(CMake)以及部分 C++ 头文件和源文件的修改。以下是对代码变更的审查意见,涵盖语法逻辑、代码质量、性能和安全四个方面:

1. 语法与逻辑

  • CMakeLists.txt:

    • find_package(Dtk${DTK_VERSION_MAJOR} ... Tools): 添加 Tools 模块依赖是合理的,这通常意味着代码中使用了 DTK 的工具类。
    • qt_add_dbus_interfaces vs dtk_add_dbus_interfaces: 代码将 org.kde.StatusNotifierItem.xml 的处理从 Qt 的标准函数移至 DTK 的封装函数 dtk_add_dbus_interfaces。这表明项目可能希望利用 DTK 对 DBus 接口生成的特定优化或定制。逻辑上没有问题,但需确保 DTK 版本确实支持此函数。
    • target_include_directories: 添加了 "${CMAKE_SOURCE_DIR}/plugins/application-tray/api/"。这是必要的,因为使用了新的 DBus 接口生成方式,生成的头文件路径可能发生变化,需要显式包含该目录。
  • C++ 代码:

    • sniprotocolhandler.cpp: m_sniInter->setSync(false); 这一行非常关键。将 DBus 调用设置为异步模式可以防止主线程阻塞,逻辑上是正确的。
    • sniprotocolhandler.h: 添加了 using namespace org::kde;。这与使用 dtk_add_dbus_interfaces 生成的新接口类命名空间相匹配。逻辑正确,但需注意命名空间污染风险(见下文代码质量部分)。
    • ddeindicatortrayprotocol.h: 移除了前向声明 class StatusNotifierItem;。既然使用了 using namespace org::kde;,该类可能不再直接被引用,或者引用方式已改变,移除是合理的。

2. 代码质量

  • 头文件包含与命名空间:

    • sniprotocolhandler.h 中直接使用 using namespace org::kde; 是一种不推荐的做法,特别是在头文件中。
    • 改进建议: 头文件应尽量保持命名空间的纯净。建议在头文件中使用全名(如 org::kde::StatusNotifierItem),或者在 .cpp 源文件中使用 using namespace。如果在头文件中必须使用,建议限制在类或函数作用域内,避免污染全局命名空间,防止与用户代码或其他库中的符号冲突。
  • 版权年份:

    • 将版权年份从 2024 修改为 2024 - 2026 是标准做法,表示代码维护周期的预期。

3. 代码性能

  • DBus 异步调用:

    • m_sniInter->setSync(false); 是一个显著的性能优化点
    • 解释: 系统托盘(Tray)涉及大量的 DBus 通信。默认情况下,某些 DBus 绑定可能是同步的(阻塞等待回复)。在 UI 线程中阻塞会导致界面卡顿(掉帧)。设置为异步 (false) 确保了 UI 的流畅性。
    • 注意: 修改为异步后,必须确保代码逻辑能够处理回调或信号,而不是依赖立即返回的值。审查片段中未显示相关逻辑,建议检查后续代码是否有相应的 QDBusPendingCallWatcher 或信号槽处理。
  • 依赖库:

    • 引入 DTK 的 Tools 模块可能会增加链接时间和二进制体积,但通常 DTK 是深度集成的,这属于可接受的架构权衡。

4. 代码安全

  • DBus 交互:
    • 代码主要涉及与 KDE StatusNotifier 协议的交互。使用 DTK 生成的接口类通常意味着遵循了 DTK 的安全规范。
    • 潜在风险: DBus 通信本质上涉及 IPC(进程间通信)。虽然异步调用提高了响应性,但也增加了并发处理的复杂性。需要确保对来自 DBus 的外部数据(如图标路径、工具提示文本)进行校验,防止注入攻击或缓冲区溢出(尽管 Qt/DTK 的字符串处理通常能缓解后者)。

总结与改进建议

这次变更主要是为了适配 DTK 的构建系统和优化 DBus 通信性能。

  1. 修改命名空间引入方式: 建议将 sniprotocolhandler.h 中的 using namespace org::kde; 移除,改在 sniprotocolhandler.cpp 中引入,或者在头文件中使用完整的类名。这能提高代码的健壮性,避免链接冲突。
  2. 检查异步逻辑: 确认 setSync(false) 后,所有依赖 m_sniInter 属性的代码都已更新为异步处理模式(例如通过信号 PropertiesChanged 或异步回调获取数据),否则可能导致空指针或使用未初始化的数据。
  3. CMake 路径: 确认 "${CMAKE_SOURCE_DIR}/plugins/application-tray/api/" 是生成的 DBus 接口头文件的最佳位置。通常生成的文件放在构建目录(CMAKE_BINARY_DIR)中更符合 CMake 的 out-of-source 构建原则,除非该目录下还包含手动编写的头文件。如果这是生成目录,建议检查是否应使用 ${CMAKE_CURRENT_BINARY_DIR}

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