Skip to content

fix(dconfig): skip release when DBus connection is closed - #594

Open
caixr23 wants to merge 1 commit into
linuxdeepin:masterfrom
caixr23:master
Open

caixr23 wants to merge 1 commit into
linuxdeepin:masterfrom
caixr23:master

Conversation

@caixr23

@caixr23 caixr23 commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

DBusBackend::~DBusBackend() always called config->release() during
destruction even if the underlying connection was already closed. On
system shutdown the global system-bus connection is being torn down
concurrently, so the async send path blocks on QDBusConnectionPrivate's
read lock and the DBus manager thread can crash with an uncaught
exception (SIGABRT).

release() just notifies dde-dconfig-daemon to drop its reference; when
the connection is already closed the message cannot be delivered anyway
and the daemon cleans up references on disconnect, so skipping the call
is safe. Guard the call with connection().isConnected() and keep the
existing exception guard.

fix: DConfig 析构时连接已关闭则跳过 release

DBusBackend::~DBusBackend() 析构时无条件调用 config->release(),即使底层
连接已关闭。系统关机时全局 system-bus 连接正被并发销毁,异步发送路径会
阻塞在 QDBusConnectionPrivate 的读锁上,DBus 管理线程可能因未捕获异常
崩溃(SIGABRT)。

release() 只是通知 dde-dconfig-daemon 减引用;连接已关闭时消息本就无法
送达,daemon 侧会在连接断开时自动清理引用,跳过该调用是安全的。用
connection().isConnected() 保护该调用,并保留原有异常兜底。

Log: 修复 deepin-service-manager 关机/重启时偶发 SIGABRT 崩溃
PMS: BUG-381521
Influence: 关机/重启时 DConfig 注销不再触发 DBus 读锁阻塞与崩溃;回归验证可观察 deepin-service-plugin@org.deepin.dde.WallpaperCache 关机时正常退出。

Summary by Sourcery

Prevent D-Bus backend destruction from propagating release failures during system shutdown.

Bug Fixes:

  • Prevent shutdown-time SIGABRT crashes by safely handling D-Bus configuration release during backend destruction.

Enhancements:

  • Skip release notifications when the D-Bus connection is already disconnected and log release exceptions without allowing them to escape the destructor.

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: caixr23

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

Comment thread src/dconfig.cpp Outdated
if (config) {
config->release();
try {
auto reply = config->release();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

这里能否不wait,保持异步处理,另外应该不需要用try cache吧,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

try cache是必须的,这里有个异常导致崩溃

@sourcery-ai

sourcery-ai Bot commented Oct 29, 2026

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

Reviewer's Guide

The destructor now synchronously waits for the asynchronous D-Bus release operation, reports reply failures, and catches exceptions to prevent shutdown-time SIGABRT caused by errors crossing the QThread boundary.

Sequence diagram for safe D-Bus release during destruction

sequenceDiagram
    participant DBusBackend
    participant DConfig
    participant SystemBus

    DBusBackend->>DConfig: release()
    DConfig-->>DBusBackend: pending reply
    DBusBackend->>DConfig: waitForFinished()
    DConfig->>SystemBus: complete release request
    SystemBus-->>DConfig: reply or error
    DConfig-->>DBusBackend: finished reply
    alt reply.isError()
        DBusBackend->>DBusBackend: qCWarning(reply.error().message())
    end
    alt release throws std::exception
        DBusBackend->>DBusBackend: qCWarning(e.what())
    end
    DBusBackend-->>DBusBackend: destructor completes without escaping exception
Loading

File-Level Changes

Change Details Files
Make D-Bus release cleanup synchronous and exception-safe during backend destruction.
  • Retain the release reply and wait for completion before destruction proceeds.
  • Log release errors returned by the pending reply.
  • Catch standard exceptions and log them so no exception escapes the destructor.
src/dconfig.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

@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/dconfig.cpp" line_range="508" />
<code_context>
-        config->release();
+        try {
+            auto reply = config->release();
+            reply.waitForFinished();
+            if (reply.isError()) {
+                qCWarning(cfLog) << "DConfig release failed:"
</code_context>
<issue_to_address>
**Shutdown stalls on release**

When the release service remains connected but does not reply promptly, `reply.waitForFinished()` blocks the destructor while the D-Bus release call awaits a reply, stalling the owning thread and delaying shutdown; delays can multiply when multiple configs are destroyed.

Avoid waiting synchronously for the release reply in the destructor, or bound the wait with a timeout.
</issue_to_address>

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

Comment thread src/dconfig.cpp Resolved
DBusBackend::~DBusBackend() always called config->release() during
destruction even if the underlying connection was already closed. On
system shutdown the global system-bus connection is being torn down
concurrently, so the async send path blocks on QDBusConnectionPrivate's
read lock and the DBus manager thread can crash with an uncaught
exception (SIGABRT).

release() just notifies dde-dconfig-daemon to drop its reference; when
the connection is already closed the message cannot be delivered anyway
and the daemon cleans up references on disconnect, so skipping the call
is safe. Guard the call with connection().isConnected() and keep the
existing exception guard.

fix: DConfig 析构时连接已关闭则跳过 release

DBusBackend::~DBusBackend() 析构时无条件调用 config->release(),即使底层
连接已关闭。系统关机时全局 system-bus 连接正被并发销毁,异步发送路径会
阻塞在 QDBusConnectionPrivate 的读锁上,DBus 管理线程可能因未捕获异常
崩溃(SIGABRT)。

release() 只是通知 dde-dconfig-daemon 减引用;连接已关闭时消息本就无法
送达,daemon 侧会在连接断开时自动清理引用,跳过该调用是安全的。用
connection().isConnected() 保护该调用,并保留原有异常兜底。

Log: 修复 deepin-service-manager 关机/重启时偶发 SIGABRT 崩溃
PMS: BUG-381521
Influence: 关机/重启时 DConfig 注销不再触发 DBus 读锁阻塞与崩溃;回归验证可观察 deepin-service-plugin@org.deepin.dde.WallpaperCache 关机时正常退出。
@caixr23 caixr23 changed the title fix(dconfig): wait for release reply in DBusBackend destructor fix(dconfig): skip release when DBus connection is closed Oct 29, 2026
@caixr23
caixr23 requested a review from 18202781743 October 29, 2026 08:52
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交修复了 DBusBackend 析构函数在 DBus 连接已断开时仍调用 release() 导致阻塞的问题。 代码通过检查连接状态跳过无效调用,并添加 try-catch 防止析构函数抛出异常,逻辑正确、注释详尽、 性能得到改善、无安全漏洞。四维度全部通过,代码质量优秀。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: ['无需修改,代码逻辑正确。']


2. 代码质量 ✅

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

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

建议: ['无需修改,注释和代码结构良好。']


3. 代码性能 ✅

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

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

建议: ['无需修改,性能改善合理。']


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: ['无需修改,安全合规。']


💡 改进建议代码示例

// 当前代码已是最佳实践,无需修改: // DBusBackend::~DBusBackend() // { //     if (config) { //         try { //             if (config->connection().isConnected()) { //                 config->release(); //             } //         } catch (const std::exception &e) { //             qCWarning(cfLog) << "DConfig release exception:" << e.what(); //         } //     } // }

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

@deepin-bot

deepin-bot Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.7.53
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #597

@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

@deepin-bot

deepin-bot Bot commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

TAG Bot

New tag: 6.7.55
DISTRIBUTION: unstable
Suggest: synchronizing this PR through rebase #607

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.

3 participants