Skip to content

fix: demote expected Identify failures to debug level - #599

Open
myml wants to merge 1 commit into
linuxdeepin:masterfrom
myml:fix/demote-expected-identify-logs
Open

myml wants to merge 1 commit into
linuxdeepin:masterfrom
myml:fix/demote-expected-identify-logs

Conversation

@myml

@myml myml commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

标题

fix: demote expected Identify failures to debug level

正文

问题

DSGApplication::getId(pid) 是 dtkcore 提供给所有应用的查询接口:给一个 PID,问
dde-application-manager 这是哪个桌面应用。

对于不属于任何桌面应用的进程(其他用户的进程、system.slice 下的系统服务、短命的
helper/子进程),AM 会正常回一个 D-Bus error(Identify failed.)。这是查询接口的
正常否定结果,但 dtkcore 在 src/dsgapplication.cpp:204 用 qCWarning 打成警告:

if (dbus_error_is_set(error.get())) {
    qCWarning(dsgApp) << "Identify from AM failed:" << error->message;
    return QByteArray();
}

调用方只要按 PID 批量查询,就会把 journal 刷满。

实测影响(UOS 25 Professional,dtkcore 6.7.47 / dde-application-manager 1.2.59)

指标 数值
deepin-defender-session-daemon 单进程产生的该行日志 474,418 行/天
峰值速率 ~180 行/秒
45 分钟窗口内该行日志 476,901 行
对照:同路径成功日志(AppId is fetched from AM) 1 行/天

journald 被这条日志打满后,所有 journald 客户端(dde-shell、kwin、桌面托盘)一起变慢,
现象是桌面卡死、鼠标拖影、MemAvailable 却还有 15 GiB——很容易被误判成内存问题。

同一时刻 AM 侧还会为每次查询再打一条 process CGroups file failed.,即一次探测两条日志,
所以两边都需要修(AM 侧的 PR 另提)。

改动

  • 只有传输层故障(无回复 / 超时 / 总线断开 / 服务不存在)保留 qCWarning;
  • 业务层的"查不到应用"降为 qCDebug。

dsgApp 分类在 release 构建下的默认级别是 QtInfoMsg(见文件头
Q_LOGGING_CATEGORY(dsgApp, "dtk.core.dsg", QtInfoMsg)),所以默认不会再输出;需要排查时:

QT_LOGGING_RULES="dtk.core.dsg.debug=true" <app>

行为兼容性:返回值完全不变(仍然是空 QByteArray),只改日志级别,任何调用方都无需改动。

验证

  • g++ -fsyntax-only 通过(Qt 6.8.0 + libdbus-1);
  • dbus_error_has_name / DBUS_ERROR_* 宏在 libdbus-1 头文件中均可用,无新增依赖;
  • 修改后在同一台机器上重启会话守护进程,journalctl --since "1 min ago" | wc -l 从
    ~22,000 行/分钟降到正常量级。

说明

更彻底的方案是在 AM 侧让 Identify 对"非应用进程"返回成功 + 空 id,而不是 D-Bus error。
但那会改变公开 D-Bus 接口语义、影响所有调用方,所以这里先做零风险的日志级别修正。

Summary by Sourcery

Reduce noise from expected desktop application identification failures while retaining visibility for genuine D-Bus transport errors.

Bug Fixes:

  • Reduce excessive journal logging when Identify correctly reports that a PID does not belong to a desktop application.
  • Preserve warnings for D-Bus transport failures while demoting expected application lookup failures to debug logging without changing return values.

DSGApplication::getId() asks dde-application-manager to identify a PID. Any
process that is not part of a desktop application - processes of other users,
system services, short-lived helpers - makes the ApplicationManager answer
with an error reply. That is a normal negative answer of a query API, not a
failure.

Logging it at warning level turns every caller that enumerates processes into
a journal flood. Measured on UOS 25 (dtkcore 6.7.47, AM 1.2.59): a single
process, deepin-defender-session-daemon, produced ~470k "Identify from AM
failed" lines per day, ~180 lines/s at peak, and the session became
unresponsive while systemd-journald was saturated.

Keep the warning for real transport failures (no reply, timeout, disconnected
bus, service unknown). The ordinary "not an application" answer remains
available with QT_LOGGING_RULES="dtk.core.dsg.debug=true".

Signed-off-by: wurongjie <wurongjie@uniontech.com>
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: myml

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 Nov 17, 2026

Copy link
Copy Markdown

Reviewer's Guide

Implementation

Keep warnings for selected D-Bus transport failures while demoting other Identify errors to debug, without changing the empty return value.

  • src/dsgapplication.cpp L204-220

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

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

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/dsgapplication.cpp" line_range="219" />
<code_context>
+            || dbus_error_has_name(error.get(), DBUS_ERROR_SERVICE_UNKNOWN)) {
+            qCWarning(dsgApp) << "Identify from AM failed:" << error->message;
+        } else {
+            qCDebug(dsgApp) << "Identify from AM failed:" << error->message;
+        }
         return QByteArray();
</code_context>
<issue_to_address>
**AM failures lose warning visibility**

When identify returns a D-Bus error outside the four listed names, `callDBusIdentifyMethod` routes the error to `qCDebug`, which release logging suppresses; it then returns an empty ID, leaving operators without a warning for the failure.

Log every Identify error reply at warning level instead of routing unlisted errors to `qCDebug`.

Also at `src/dsgapplication.cpp:213-216`.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread src/dsgapplication.cpp
|| dbus_error_has_name(error.get(), DBUS_ERROR_SERVICE_UNKNOWN)) {
qCWarning(dsgApp) << "Identify from AM failed:" << error->message;
} else {
qCDebug(dsgApp) << "Identify from AM failed:" << error->message;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Medium · AM failures lose warning visibility

When identify returns a D-Bus error outside the four listed names, callDBusIdentifyMethod routes the error to qCDebug, which release logging suppresses; it then returns an empty ID, leaving operators without a warning for the failure.

Log every Identify error reply at warning level instead of routing unlisted errors to qCDebug.

Also at src/dsgapplication.cpp:213-216.

Prompt for AI agents
In `src/dsgapplication.cpp` at line 219:

**AM failures lose warning visibility**

When identify returns a D-Bus error outside the four listed names, `callDBusIdentifyMethod` routes the error to `qCDebug`, which release logging suppresses; it then returns an empty ID, leaving operators without a warning for the failure.

Log every Identify error reply at warning level instead of routing unlisted errors to `qCDebug`.

Also at `src/dsgapplication.cpp:213-216`.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交将D-Bus Identify调用中预期的错误回复从warning降级为debug日志,有效解决了journal日志泛滥问题(约470k行/天)。代码逻辑清晰,注释详尽,无安全漏洞,性能得到改善。四维度均通过,OCR审查也无发现问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 语法正确,逻辑清晰 ✅ 通过

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

建议: []


2. 代码质量 ✅

评价: 代码结构清晰,注释完整 ✅ 通过

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

建议: ['建议:若未来需要检查的错误类型增多,可考虑将错误名列表提取为数组并循环检查,减少重复代码。当前4个条件无需重构。']


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 当前代码已为最佳实践,无需修改。
// 若未来需要更灵活的错误分类,可考虑如下重构:
//
// static const char *transport_errors[] = {
//     DBUS_ERROR_NO_REPLY,
//     DBUS_ERROR_TIMEOUT,
//     DBUS_ERROR_DISCONNECTED,
//     DBUS_ERROR_SERVICE_UNKNOWN,
// };
//
// bool is_transport_error = false;
// for (const char *err_name : transport_errors) {
//     if (dbus_error_has_name(error.get(), err_name)) {
//         is_transport_error = true;
//         break;
//     }
// }
//
// if (is_transport_error) {
//     qCWarning(dsgApp) << "Identify from AM failed:" << error->message;
// } else {
//     qCDebug(dsgApp) << "Identify from AM failed:" << error->message;
// }

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

@deepin-bot

deepin-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.7.54
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #600

This branch has not been deployed

No deployments
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