Skip to content

fix(service): register D-Bus object before service name to close race - #487

Merged
lzwind merged 1 commit into
linuxdeepin:masterfrom
lzwind:master
Jul 15, 2026
Merged

fix(service): register D-Bus object before service name to close race#487
lzwind merged 1 commit into
linuxdeepin:masterfrom
lzwind:master

Conversation

@lzwind

@lzwind lzwind commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Register the /com/deepin/logviewer object before requesting the well-known name, so the object tree is ready once the name is visible.

先注册对象再注册服务名,消除名称已注册但对象未注册的竞态窗口,
避免 busctl tree 间歇性报 "No such object path '/'"。

Log: 修复服务列表获取间歇性失败的问题
Influence: D-Bus 按需激活后,客户端首次 introspect 不再因竞态丢失对象树, busctl tree 获取服务对象列表稳定可用。

Summary by Sourcery

Bug Fixes:

  • Fix intermittent failures when retrieving the D-Bus service object tree (e.g., busctl tree reporting missing root object) caused by the service name becoming visible before the object is registered.

@sourcery-ai

sourcery-ai Bot commented Jul 15, 2026

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

Reviewer's Guide

This PR fixes a D-Bus race by registering the log viewer service’s object path before claiming the well-known service name, ensuring the object tree is ready once the name becomes visible on the system bus.

Sequence diagram for revised D-Bus service and object registration order

sequenceDiagram
    participant Service as LogViewerService
    participant SystemBus as QDBusConnection_systemBus
    actor Client as D-Bus_client

    Service->>SystemBus: registerObject(LogViewrPath,&service,QDBusConnection::ExportAllSlots)
    SystemBus-->>Service: registerObject success
    Service->>SystemBus: registerService(LogViewrServiceName)
    SystemBus-->>Service: registerService success (name visible)

    Client->>SystemBus: org.freedesktop.DBus.Introspectable.Introspect
    SystemBus-->>Client: returns complete object tree for /com/deepin/logviewer
Loading

File-Level Changes

Change Details Files
Reorder D-Bus registration so the service object is registered before the well-known service name to eliminate a race that caused intermittent missing object trees.
  • Instantiate the LogViewerService before registering its D-Bus object path.
  • Register the /com/deepin/logviewer object on the system bus prior to claiming the well-known service name.
  • Move the registerService call to after successful registerObject and preserve existing error handling and exit codes.
  • Add explanatory comments describing the race condition and the rationale for the new registration order.
logViewerService/main.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 reviewed your changes and they look great!


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.

@github-actions

Copy link
Copy Markdown
  • 检测到敏感词export变动
详情
    {
    "export": {
        "application/assets/com.deepin.pkexec.logViewerAuth.policy": {
            "a": [
                "\t\t<message xml:lang=\"fr\">L'authentification est requise pour exporter les journaux</message>",
                "\t\t<message xml:lang=\"es\">Se requiere autenticaci\u00f3n para exportar registros</message>",
                "\t\t<message xml:lang=\"pt\">\u00c9 necess\u00e1ria autentica\u00e7\u00e3o para exportar registos</message>",
                "\t\t<message xml:lang=\"fr\">L'authentification est requise pour exporter les journaux</message>",
                "\t\t<message xml:lang=\"es\">Se requiere autenticaci\u00f3n para exportar registros</message>",
                "\t\t<message xml:lang=\"pt\">\u00c9 necess\u00e1ria autentica\u00e7\u00e3o para exportar registos</message>"
            ],
            "b": [
                "\t\t<message xml:lang=\"ast\">La autenticaci\u00f3n ye necesaria pa exportar llogs</message>",
                "\t\t<message xml:lang=\"br\">\u00c9 necess\u00e1rio autentica\u00e7\u00e3o para exportar logs</message>",
                "\t\t<message xml:lang=\"cs\">Pro exportov\u00e1n\u00ed z\u00e1znam\u016f je vy\u017eadov\u00e1no ov\u011b\u0159en\u00ed</message>",
                "\t\t<message xml:lang=\"en_AU\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"en_CA\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"en_GB\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"es\">Se requiere autenticaci\u00f3n para exportar registros</message>",
                "\t\t<message xml:lang=\"fil\">Kailangan ang pag-authenticate upang i-export ang mga log</message>",
                "\t\t<message xml:lang=\"fr\">L'authentification est requise pour exporter les journaux</message>",
                "\t\t<message xml:lang=\"gl_ES\">\u00c9 necesario a autenticaci\u00f3n para exportar os rexistros</message>",
                "\t\t<message xml:lang=\"ia\">Autentificacion necesaria por exportar le logs</message>",
                "\t\t<message xml:lang=\"la\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"pam\">Kin kinahanglan ang pag-authentication para mag-export hin logs</message>",
                "\t\t<message xml:lang=\"pt\">\u00c9 necess\u00e1ria autentica\u00e7\u00e3o para exportar registos</message>",
                "\t\t<message xml:lang=\"pt_BR\">A autentica\u00e7\u00e3o \u00e9 necess\u00e1ria para exportar os logs</message>",
                "\t\t<message xml:lang=\"ro\">Autentificarea este necesar\u0103 pentru a exporta jurnalul</message>",
                "\t\t<message xml:lang=\"sk\">Prihl\u00e1senie je vy\u017eadovan\u00e9 na export logov</message>",
                "\t\t<message xml:lang=\"sv\">Autentisering kr\u00e4vs f\u00f6r att exportera loggar</message>",
                "\t\t<message xml:lang=\"ast\">La autenticaci\u00f3n ye necesaria pa exportar llogs</message>",
                "\t\t<message xml:lang=\"br\">\u00c9 necess\u00e1rio autentica\u00e7\u00e3o para exportar logs</message>",
                "\t\t<message xml:lang=\"cs\">Pro exportov\u00e1n\u00ed z\u00e1znam\u016f je vy\u017eadov\u00e1no ov\u011b\u0159en\u00ed</message>",
                "\t\t<message xml:lang=\"en_AU\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"en_CA\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"en_GB\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"es\">Se requiere autenticaci\u00f3n para exportar registros</message>",
                "\t\t<message xml:lang=\"fil\">Kailangan ang pag-authenticate upang i-export ang mga log</message>",
                "\t\t<message xml:lang=\"fr\">L'authentification est requise pour exporter les journaux</message>",
                "\t\t<message xml:lang=\"gl_ES\">\u00c9 necesario a autenticaci\u00f3n para exportar os rexistros</message>",
                "\t\t<message xml:lang=\"ia\">Autentificacion necesaria por exportar le logs</message>",
                "\t\t<message xml:lang=\"la\">Authentication is required to export logs</message>",
                "\t\t<message xml:lang=\"pam\">Kin kinahanglan ang pag-authentication para mag-export hin logs</message>",
                "\t\t<message xml:lang=\"pt\">\u00c9 necess\u00e1ria autentica\u00e7\u00e3o para exportar registos</message>",
                "\t\t<message xml:lang=\"pt_BR\">A autentica\u00e7\u00e3o \u00e9 necess\u00e1ria para exportar os logs</message>",
                "\t\t<message xml:lang=\"ro\">Autentificarea este necesar\u0103 pentru a exporta jurnalul</message>",
                "\t\t<message xml:lang=\"sk\">Prihl\u00e1senie je vy\u017eadovan\u00e9 na export logov</message>",
                "\t\t<message xml:lang=\"sv\">Autentisering kr\u00e4vs f\u00f6r att exportera loggar</message>"
            ]
        }
    }
}

Register the /com/deepin/logviewer object before requesting the
well-known name, so the object tree is ready once the name is visible.

先注册对象再注册服务名,消除名称已注册但对象未注册的竞态窗口,
避免 busctl tree 间歇性报 "No such object path '/'"。

Log: 修复服务列表获取间歇性失败的问题
Influence: D-Bus 按需激活后,客户端首次 introspect 不再因竞态丢失对象树,
busctl tree 获取服务对象列表稳定可用。
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

★ 总体评分:95分

■ 【总体评价】

代码通过调整D-Bus注册顺序有效修复了服务名与对象路径注册的竞态条件
逻辑正确且注释清晰,无安全漏洞,代码质量优秀

■ 【详细分析】

  • 1.语法逻辑(正确)✓

main函数中将registerService移至registerObject之后,确保了在well-known name对外可见时对象路径已就绪,消除了竞态窗口
潜在问题:无
建议:无

  • 2.代码质量(优秀)✓

新增的注释准确描述了修改原因及对应的错误现象,版权年份更新合理
潜在问题:无
建议:无

  • 3.代码性能(无性能问题)✓

仅调整了函数调用顺序,未引入额外的计算或资源开销
潜在问题:无
建议:无

  • 4.代码安全(存在0个安全漏洞)✓

漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个
本次修改修复了原有的竞态条件导致的间歇性拒绝服务问题,未引入新的安全漏洞

  • 建议:无

■ 【改进建议代码示例】

// SPDX-FileCopyrightText: 2019 - 2026 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

// ... 其他代码 ...

    QDBusConnection systemBus = QDBusConnection::systemBus();
    // 先注册对象再注册服务名:well-known name 一旦对外可见,/com/deepin/logviewer
    // 对象必然已就绪,消除名称已注册但对象尚未注册的竞态窗口
    // (表现为 busctl tree 间歇性 "No such object path '/'")。
    LogViewerService service;
    if (!systemBus.registerObject(LogViewrPath,
                                  &service,
                                  QDBusConnection::ExportAllSlots | QDBusConnection::ExportAllSignals)) {
        qCCritical(logService) << "registerObject failed:" << systemBus.lastError();
        exit(0x0002);
    }
    if (!systemBus.registerService(LogViewrServiceName)) {
        qCCritical(logService) << "registerService failed:" << systemBus.lastError();
        exit(0x0001);
    }
    return a.exec();

@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lzwind, wyu71

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

@lzwind
lzwind merged commit a259c14 into linuxdeepin:master Jul 15, 2026
22 of 23 checks passed
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