Skip to content

fix(power): avoid 25s stall when blanking the screen - #217

Merged
deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
fly602:fix/power-lockfront-deadlock
Nov 18, 2026
Merged

deepin-bot[bot] merged 1 commit into
linuxdeepin:masterfrom
fly602:fix/power-lockfront-deadlock

Conversation

@fly602

@fly602 fly602 commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

Bug: https://pms.uniontech.com/bug-view-382691.html

fix(power): avoid 25s stall when blanking the screen

  1. TurnOffScreen waited for LockFront ShowAuth while dde-lock read Power1
    SleepLock back, so both sides stalled until the 25s D-Bus timeout and
    the display stayed lit the whole time.
  2. SessionDBusProxy::showLockAuth fire-and-forgets ShowAuth now, and the
    X11 turn-off path blanks the screen before requesting the lock.
  3. dde-shortcut-tool's power controller uses the same async ShowAuth call,
    so the power-button shortcut no longer blocks its key handler.

Log: Blank the screen immediately instead of waiting for LockFront.

Influence:

  1. Press the power button: the display blanks immediately; journalctl shows
    no 25s gap between "Locking session" and "Setting DPMS mode to off".
  2. Lock/unlock, suspend/resume, hibernate and shutdown still work.
  3. Repeat screen-off after a suspend/resume cycle and confirm the display
    still blanks immediately.

fix(power): 修复锁屏回读导致关屏延迟 25 秒

  1. TurnOffScreen 同步等待 LockFront ShowAuth,而 dde-lock 在 ShowAuth
    中回读 Power1 SleepLock,双方互等到 25 秒 D-Bus 超时,期间屏幕
    一直亮着。
  2. SessionDBusProxy::showLockAuth 改为异步发送 ShowAuth 后立即返回,
    X11 关屏路径先关闭显示器再请求锁屏。
  3. dde-shortcut-tool 的电源控制器同样改为异步调用 ShowAuth,按电源键
    不再阻塞快捷键处理。

Log: 立即关闭显示器,不再等待 LockFront 返回。

Influence:

  1. 按电源键后显示器立即熄灭;journalctl 中 "Locking session" 到
    "Setting DPMS mode to off" 不再有 25 秒间隔。
  2. 锁屏/解锁、待机/唤醒、休眠、关机功能正常。
  3. 待机/唤醒后再按一次电源键,确认显示器仍立即关闭。

PMS: BUG-382691

Summary by Sourcery

Avoid power-button screen-off delays by blanking the display immediately and making lock-authentication requests asynchronous.

Bug Fixes:

  • Prevent screen-off operations from stalling for the D-Bus timeout when locking the session.
  • Ensure power-button locking no longer blocks shortcut handling while requesting lock authentication.

Enhancements:

  • Blank the display before initiating session locking so power-button screen-off is immediate.

@sourcery-ai

sourcery-ai Bot commented Nov 10, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Uses of the API

Send LockFront ShowAuth asynchronously in both power paths so waiting for its reply cannot block the caller.

  • src/plugin-qt/power/session/sessiondbusproxy.cpp L340-346
  • src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp L278-280

Implementation

Blank the display before requesting the lock so the lock operation cannot delay DPMS shutdown.

  • src/plugin-qt/power/session/powermanager.cpp L635 (removed lines), L637-641

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 2 issues

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

## Individual Comments

### Comment 1
<location path="src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp" line_range="280" />
<code_context>
-    lockFront.call("ShowAuth", autoStartAuth);
+    // Fire and forget: LockFront reads Power1 back, so waiting for its reply
+    // from a key handler only risks the 25s D-Bus timeout.
+    lockFront.asyncCall("ShowAuth", autoStartAuth);
 }

</code_context>
<issue_to_address>
**Session resumes unlocked**

When lockFront does not process the request within the fixed 500 ms pause, `handleSystemSuspend()` calls `systemSuspend()` without confirming `ShowAuth` completed, so the machine suspends before the session is locked and resumes to an unlocked session.

Wait for confirmation that `ShowAuth` has completed before calling `systemSuspend()`.
</issue_to_address>

### Comment 2
<location path="src/plugin-qt/power/session/powermanager.cpp" line_range="639-641" />
<code_context>

+    // Blank first: locking goes through LockFront, which reads Power1 back, so
+    // it must never gate how long the display stays lit.
     setDPMSModeOff();
+    if (m_screenBlackLock)
+        doLock(true);

     SetPrepareSuspend(PS_Finish);
</code_context>
<issue_to_address>
**Wake can precede locking**

When the user presses the power button again while LockFront has not yet processed the first asynchronous lock request, `TurnOffScreen()` blanks the display before the asynchronous lock request takes effect. A second power-button press sees the display off and turns it back on, exposing the still-unlocked session until LockFront handles the pending request.

Track the pending lock and prevent waking the display until the session is locked, or otherwise ensure the lock takes effect before exposing the screen.
</issue_to_address>

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

lockFront.call("ShowAuth", autoStartAuth);
// Fire and forget: LockFront reads Power1 back, so waiting for its reply
// from a key handler only risks the 25s D-Bus timeout.
lockFront.asyncCall("ShowAuth", autoStartAuth);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟠 High · Session resumes unlocked

When lockFront does not process the request within the fixed 500 ms pause, handleSystemSuspend() calls systemSuspend() without confirming ShowAuth completed, so the machine suspends before the session is locked and resumes to an unlocked session.

Wait for confirmation that ShowAuth has completed before calling systemSuspend().

Prompt for AI agents
In `src/plugin-qt/shortcut/tools/dde-shortcut-tool/powercontroller.cpp` at line 280:

**Session resumes unlocked**

When lockFront does not process the request within the fixed 500 ms pause, `handleSystemSuspend()` calls `systemSuspend()` without confirming `ShowAuth` completed, so the machine suspends before the session is locked and resumes to an unlocked session.

Wait for confirmation that `ShowAuth` has completed before calling `systemSuspend()`.

@fly602
fly602 force-pushed the fix/power-lockfront-deadlock branch 2 times, most recently from 4a4e884 to efa7382 Compare November 11, 2026 02:20
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: fly602, mhduiy

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

1. TurnOffScreen waited for LockFront ShowAuth while dde-lock read Power1
   SleepLock back, so both sides stalled until the 25s D-Bus timeout and
   the display stayed lit the whole time.
2. SessionDBusProxy::showLockAuth fire-and-forgets ShowAuth now, and the
   X11 turn-off path blanks the screen before requesting the lock.
3. dde-shortcut-tool's power controller uses the same async ShowAuth call,
   so the power-button shortcut no longer blocks its key handler.

Log: Blank the screen immediately instead of waiting for LockFront.

Influence:
1. Press the power button: the display blanks immediately; journalctl shows
   no 25s gap between "Locking session" and "Setting DPMS mode to off".
2. Lock/unlock, suspend/resume, hibernate and shutdown still work.
3. Repeat screen-off after a suspend/resume cycle and confirm the display
   still blanks immediately.

fix(power): 修复锁屏回读导致关屏延迟 25 秒

1. TurnOffScreen 同步等待 LockFront ShowAuth,而 dde-lock 在 ShowAuth
   中回读 Power1 SleepLock,双方互等到 25 秒 D-Bus 超时,期间屏幕
   一直亮着。
2. SessionDBusProxy::showLockAuth 改为异步发送 ShowAuth 后立即返回,
   X11 关屏路径先关闭显示器再请求锁屏。
3. dde-shortcut-tool 的电源控制器同样改为异步调用 ShowAuth,按电源键
   不再阻塞快捷键处理。

Log: 立即关闭显示器,不再等待 LockFront 返回。

Influence:
1. 按电源键后显示器立即熄灭;journalctl 中 "Locking session" 到
   "Setting DPMS mode to off" 不再有 25 秒间隔。
2. 锁屏/解锁、待机/唤醒、休眠、关机功能正常。
3. 待机/唤醒后再按一次电源键,确认显示器仍立即关闭。

PMS: BUG-382691
@fly602
fly602 force-pushed the fix/power-lockfront-deadlock branch from efa7382 to 308d430 Compare November 18, 2026 06:32
@deepin-ci-robot

Copy link
Copy Markdown

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 本次提交聚焦于修复息屏时因 LockFront 同步读取 Power1 属性导致的 25 秒卡顿问题,通过将阻塞式 D-Bus 调用改为异步调用并调整息屏与加锁的执行顺序,从根本上消除了主线程阻塞。三处变更均与 commit 目的严格吻合,注释清晰说明设计意图,无安全漏洞、无性能隐患、无逻辑缺陷,OCR 审查同样未发现问题。

🔍 详细分析

1. 语法逻辑 ✅

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

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

建议: []


2. 代码质量 ✅

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

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

建议: []


3. 代码性能 ✅

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

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

建议: []


4. 代码安全 🔒

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

🔐 发现 0 个安全漏洞

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

建议: []


💡 改进建议代码示例

// 当前实现已为正确做法,无需修改。建议保持:
// sessiondbusproxy.cpp - 异步调用避免阻塞主线程
void SessionDBusProxy::showLockAuth(bool autoStart)
{
    QDBusMessage msg = QDBusMessage::createMethodCall(
        kLockFront, kLockFrontPath, kLockFront, QStringLiteral("ShowAuth"));
    msg << autoStart;
    QDBusConnection::sessionBus().asyncCall(msg);
}

// powercontroller.cpp - fire and forget
lockFront.asyncCall("ShowAuth", autoStartAuth);

// powermanager.cpp - 先息屏再上锁,避免 LockFront 同步读取 Power1 阻塞息屏
setDPMSModeOff();
if (m_screenBlackLock)
    doLock(true);

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

@fly602

fly602 commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

/forcemerge

@deepin-bot

deepin-bot Bot commented Nov 18, 2026

Copy link
Copy Markdown

This pr force merged! (status: blocked)

@deepin-bot
deepin-bot Bot merged commit 7391dcb into linuxdeepin:master Nov 18, 2026
9 of 10 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