fix: delay authentication creation after system wake - #530
Conversation
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
Reviewer's guide (collapsed on small PRs)Reviewer's GuideIntroduces 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 authenticationsequenceDiagram
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
State diagram for wake-up authentication timerstateDiagram-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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review🤖 AI 代码审查报告📊 总体评价
🔍 详细分析1. 语法逻辑 ✅评价: 优秀 ✅ 通过 潜在问题: 建议: 语法正确,逻辑清晰。QTimer 初始化使用 parent-child 机制管理内存,lambda 连接使用 this 作为 context 确保安全。单次触发定时器的 start/stop 逻辑正确,在所有非认证状态都正确停止定时器。 2. 代码质量 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 建议为 300ms 定时器间隔添加注释说明选择依据,例如:// 300ms 延迟确保系统唤醒状态稳定后再创建认证,避免竞态条件 3. 代码性能 ✅评价: 优秀 ✅ 通过 潜在问题:
建议: 建议将 300ms 定义为常量(如 static const int kWakeUpAuthDelayMs = 300;),便于后续维护和调整。单次触发定时器设计合理,start() 重复调用会重启定时器,实现正确的防抖行为。 4. 代码安全 🔒评价: 优秀 ✅ 通过
安全漏洞详情: 建议: 存在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
left a comment
There was a problem hiding this comment.
dde-session-shell仓库修改
|
[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. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
m_wakeUpAuthTimer(300ms single-shot) to postpone authentication creation after system wake-upcreateAuthentication()calls in system wake and active change flows with timer-triggered executionLog: Fix potential lock screen flash or authentication failure after system wake-up
Influence:
fix: 延迟系统唤醒后的认证创建
m_wakeUpAuthTimer(300ms 单次触发)来延迟系统唤醒后的认 证创建createAuthentication()调用替 换为定时器触发执行Log: 修复系统唤醒后可能出现的锁屏闪烁或认证失败问题
Influence:
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:
Enhancements: