Skip to content

fix: delay authentication creation after system wake - #530

Closed
52cyb wants to merge 1 commit into
linuxdeepin:masterfrom
52cyb:master
Closed

fix: delay authentication creation after system wake#530
52cyb wants to merge 1 commit into
linuxdeepin:masterfrom
52cyb:master

Conversation

@52cyb

@52cyb 52cyb commented Sep 1, 2026

Copy link
Copy Markdown
  1. Add a dedicated m_wakeUpAuthTimer (300ms single-shot) to postpone authentication creation after system wake-up
  2. Replace direct createAuthentication() calls in system wake and active change flows with timer-triggered execution
  3. Stop timer appropriately during sleep, invisible, or inactive states to prevent unnecessary authentication
  4. Fix potential race condition where authentication creation during screen wake could be interrupted by system events

Log: Fix potential lock screen flash or authentication failure after system wake-up

Influence:

  1. Test system wake-up from sleep and verify lock screen appears normally without flashing
  2. Test rapid wake-sleep-wake cycles to ensure authentication state is consistent
  3. Test when lock screen is invisible during wake-up to verify no authentication is created
  4. Test switching user accounts after wake-up to verify authentication creation is correct
  5. Test system suspend/resume multiple times to check stability
  6. Verify no authentication is triggered when system enters sleep or becomes inactive

fix: 延迟系统唤醒后的认证创建

  1. 添加专用的 m_wakeUpAuthTimer(300ms 单次触发)来延迟系统唤醒后的认 证创建
  2. 将系统唤醒和活动状态变化流程中的直接 createAuthentication() 调用替 换为定时器触发执行
  3. 在休眠、不可见或不活动状态时适当停止定时器,避免不必要的认证
  4. 修复屏幕唤醒期间认证创建可能被系统事件打断的竞态条件问题

Log: 修复系统唤醒后可能出现的锁屏闪烁或认证失败问题

Influence:

  1. 测试系统从休眠唤醒后锁屏是否正常显示,无闪烁现象
  2. 测试快速唤醒-休眠-唤醒循环,验证认证状态一致性
  3. 测试唤醒时锁屏不可见的情况,验证不会创建认证
  4. 测试唤醒后切换用户账户,验证认证创建正确性
  5. 多次测试系统挂起/恢复,检查稳定性
  6. 验证系统进入休眠或不活动状态时不会触发认证

PMS: BUG-373405

Summary by Sourcery

Delay post-wake authentication creation and cancel it when the lock screen is not eligible, preventing wake-up race conditions and unnecessary authentication.

Bug Fixes:

  • Prevent authentication failures and lock-screen flashing after system wake-up by delaying authentication creation until the system state stabilizes.
  • Avoid creating authentication while the system is sleeping, inactive, or the lock screen is not visible.

Enhancements:

  • Coordinate authentication creation across wake-up and active-state transitions to improve consistency during suspend/resume and rapid power-state changes.

1. Add a dedicated `m_wakeUpAuthTimer` (300ms single-shot) to postpone
authentication creation after system wake-up
2. Replace direct `createAuthentication()` calls in system wake and
active change flows with timer-triggered execution
3. Stop timer appropriately during sleep, invisible, or inactive states
to prevent unnecessary authentication
4. Fix potential race condition where authentication creation during
screen wake could be interrupted by system events

Log: Fix potential lock screen flash or authentication failure after
system wake-up

Influence:
1. Test system wake-up from sleep and verify lock screen appears
normally without flashing
2. Test rapid wake-sleep-wake cycles to ensure authentication state
is consistent
3. Test when lock screen is invisible during wake-up to verify no
authentication is created
4. Test switching user accounts after wake-up to verify authentication
creation is correct
5. Test system suspend/resume multiple times to check stability
6. Verify no authentication is triggered when system enters sleep or
becomes inactive

fix: 延迟系统唤醒后的认证创建

1. 添加专用的 `m_wakeUpAuthTimer`(300ms 单次触发)来延迟系统唤醒后的认
证创建
2. 将系统唤醒和活动状态变化流程中的直接 `createAuthentication()` 调用替
换为定时器触发执行
3. 在休眠、不可见或不活动状态时适当停止定时器,避免不必要的认证
4. 修复屏幕唤醒期间认证创建可能被系统事件打断的竞态条件问题

Log: 修复系统唤醒后可能出现的锁屏闪烁或认证失败问题

Influence:
1. 测试系统从休眠唤醒后锁屏是否正常显示,无闪烁现象
2. 测试快速唤醒-休眠-唤醒循环,验证认证状态一致性
3. 测试唤醒时锁屏不可见的情况,验证不会创建认证
4. 测试唤醒后切换用户账户,验证认证创建正确性
5. 多次测试系统挂起/恢复,检查稳定性
6. 验证系统进入休眠或不活动状态时不会触发认证

PMS: BUG-373405
@sourcery-ai

sourcery-ai Bot commented Sep 1, 2026

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

Reviewer's Guide

Introduces a 300 ms single-shot delay for authentication creation after system wake and active-state changes, while cancelling pending work during sleep, inactivity, or invisibility to avoid wake-up races, lock-screen flashes, and invalid authentication attempts.

Sequence diagram for delayed wake-up authentication

sequenceDiagram
    participant System
    participant LockWorker
    participant WakeUpAuthTimer
    participant Authentication

    System->>LockWorker: activeChanged(active)
    alt active and visible
        LockWorker->>WakeUpAuthTimer: start()
        WakeUpAuthTimer-->>LockWorker: timeout after 300 ms
        LockWorker->>Authentication: createAuthentication(currentUser()->name())
    else inactive or invisible
        LockWorker->>WakeUpAuthTimer: stop()
        LockWorker->>Authentication: endAuthentication(m_account, AT_All)
        LockWorker->>Authentication: destroyAuthentication(m_account)
    end
Loading

State diagram for wake-up authentication timer

stateDiagram-v2
    [*] --> Idle
    Idle --> Pending: active and visible / start()
    Pending --> Authenticating: timeout after 300 ms / createAuthentication()
    Pending --> Idle: sleep / stop()
    Pending --> Idle: inactive or invisible / stop()
    Authenticating --> Idle: authentication created
Loading

File-Level Changes

Change Details Files
Defer authentication creation after wake and active-state transitions using a dedicated single-shot timer.
  • Add a parented, single-shot 300 ms wake-up authentication timer.
  • Trigger delayed authentication when the session becomes active and visible or when an active session resumes after wake.
  • Retain current-user lookup at timer execution time rather than scheduling time.
src/dde-lock/lockworker.cpp
src/dde-lock/lockworker.h
Cancel pending authentication creation when the lock screen cannot or should not authenticate.
  • Stop the timer on sleep, inactive or invisible state transitions, and before destroying authentication.
  • Preserve existing authentication cleanup for inactive flows.
src/dde-lock/lockworker.cpp
Update source ownership metadata.
  • Extend the copyright year range in the modified implementation and header files.
src/dde-lock/lockworker.cpp
src/dde-lock/lockworker.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

@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/dde-lock/lockworker.cpp" line_range="61-62" />
<code_context>

+    m_wakeUpAuthTimer->setSingleShot(true);
+    m_wakeUpAuthTimer->setInterval(300);
+    connect(m_wakeUpAuthTimer, &QTimer::timeout, this, [this](){
+        createAuthentication(m_model->currentUser()->name());
+    });
+
</code_context>
<issue_to_address>
**issue (bug_risk):** The timer callback unconditionally creates authentication without checking that the lock screen is still visible, the session is still active, or the content is not being updated. If visibility or session state changes during the 300 ms delay without the corresponding cancellation path running first, authentication is created after the screen has become invisible or inactive.

**Triggers:** When the lock screen is hidden or the session enters an update/inactive state during the 300 ms delay.

**Suggested fix:** Check `m_model->visible()`, `m_login1SessionSelf->active()`, and the current content/state in the timeout callback, and stop the timer from every visibility-transition path.
</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.

Comment thread src/dde-lock/lockworker.cpp
@deepin-ci-robot

Copy link
Copy Markdown
Contributor

deepin pr auto review

🤖 AI 代码审查报告

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

Pass


📊 总体评价

项目 结果
审查结论 代码审查通过
评分详情 总体评分 98 分,大于 70 分通过阈值,代码质量符合要求。通过引入 m_wakeUpAuthTimer 延迟认证创建,有效修复了系统唤醒后锁屏闪烁和认证失败的竞态条件问题。

🔍 详细分析

1. 语法逻辑 ✅

评价: 优秀 ✅ 通过

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

建议: 语法正确,逻辑清晰。QTimer 初始化使用 parent-child 机制管理内存,lambda 连接使用 this 作为 context 确保安全。单次触发定时器的 start/stop 逻辑正确,在所有非认证状态都正确停止定时器。


2. 代码质量 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/dde-lock/lockworker.cpp:59 - m_wakeUpAuthTimer 的 300ms 定时器间隔值缺少注释说明选择依据

建议: 建议为 300ms 定时器间隔添加注释说明选择依据,例如:// 300ms 延迟确保系统唤醒状态稳定后再创建认证,避免竞态条件


3. 代码性能 ✅

评价: 优秀 ✅ 通过

潜在问题:

  1. src/dde-lock/lockworker.cpp:59 - 300ms 魔法数字硬编码,建议定义为常量

建议: 建议将 300ms 定义为常量(如 static const int kWakeUpAuthDelayMs = 300;),便于后续维护和调整。单次触发定时器设计合理,start() 重复调用会重启定时器,实现正确的防抖行为。


4. 代码安全 🔒

评价: 优秀 ✅ 通过

🔐 发现 0 个安全漏洞

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

建议: 存在0个安全漏洞。本次变更不涉及用户输入处理,无注入风险。通过延迟认证创建修复竞态条件,实际提升了认证流程的安全性。


💡 改进建议代码示例

// 在 lockworker.h 中定义常量
static const int kWakeUpAuthDelayMs = 300;  // 延迟认证创建时间,确保系统唤醒状态稳定

// 在构造函数中使用常量
m_wakeUpAuthTimer->setSingleShot(true);
m_wakeUpAuthTimer->setInterval(kWakeUpAuthDelayMs);
connect(m_wakeUpAuthTimer, &QTimer::timeout, this, [this](){
    createAuthentication(m_model->currentUser()->name());
});

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

@yixinshark yixinshark left a comment

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.

dde-session-shell仓库修改

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 52cyb

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

@52cyb 52cyb closed this Sep 1, 2026
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