fix(reader): fix render thread quit race and adapt page-change unit test - #373
Conversation
Remove the unconditional m_quit reset in run(): if destroyForever() set the quit flag before the thread entered run(), the reset swallowed the request and wait() blocked forever at process exit. Make m_quit atomic and stub isVisible/sidebar in the unit test to match the new visibility guard added for reading-progress restore. run() 不再无条件重置 m_quit,避免吞掉 destroyForever 的退出请求, 导致进程退出阶段 wait() 永久阻塞;m_quit 改为原子量消除数据竞争。 单测补 isVisible/sidebar 桩,适配阅读进度恢复新增的可见性守卫。 Log: 修复渲染线程退出竞争挂死并适配页码变化单测 Influence: 渲染线程退出时序修复,应用退出更稳;单测恢复全部通过。
Reviewer's guide (collapsed on small PRs)Reviewer's GuideFixes a shutdown race where PageRenderThread could overwrite a pre-start quit request and block forever in wait(), using an atomic quit flag and preserving its initial state. The affected page-change unit test now stubs visibility and sidebar updates to match the production guard without triggering render-thread activity. Sequence diagram for the PageRenderThread shutdown race fixsequenceDiagram
participant MainThread
participant PageRenderThread
MainThread->>PageRenderThread: destroyForever()
PageRenderThread->>PageRenderThread: m_quit = true
MainThread->>PageRenderThread: start()
PageRenderThread->>PageRenderThread: run()
PageRenderThread->>PageRenderThread: read atomic m_quit
PageRenderThread-->>MainThread: exits run()
MainThread->>PageRenderThread: wait()
Sequence diagram for the guarded page-change unit testsequenceDiagram
participant Test
participant DocSheet
participant Browser
participant SheetSidebar
Test->>Browser: isVisible()
Browser-->>DocSheet: true
DocSheet->>SheetSidebar: setCurrentPage()
SheetSidebar-->>Test: page updated
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
deepin pr auto reviewAI 代码审查报告
总体评价
本次 PR 修复了 漏洞统计
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 四维度评分维度1:语法逻辑 ✓(25/25 分)
分析:
无编译错误,无逻辑缺陷,边界条件处理完善。 维度2:代码质量 ✓(25/25 分)
分析:
维度3:代码性能 ✓(20/20 分)
分析:
维度4:代码安全 ✓(30/30 分)
分析: 本次变更不仅未引入安全漏洞,还修复了一个数据竞争(C++ 中的未定义行为),是安全改进:
漏洞对比统计:新增漏洞 0 个,减少漏洞 0 个,持平 0 个 修改文件详情1. reader/browser/PageRenderThread.h
评价:正确将跨线程访问的标志位改为原子类型,消除数据竞争。 2. reader/browser/PageRenderThread.cpp| 变更类型 | 内容 | 评价:核心修复点。移除 3. tests/uiframe/ut_docsheet.cpp
评价:测试适配合理。 改进建议本次 PR 代码质量优秀,无安全漏洞,无改进建议。代码变更精准解决了竞态条件问题,注释详尽,测试适配合理。 审查结论本次 PR 是一个高质量的 Bug 修复提交:
建议合并。 |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: add-uos, lzwind 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 |
问题 / Problem
PageRenderThread::destroyForever()在线程进入run()前设置m_quit = true,会被run()第一行的m_quit = false无条件覆盖,导致wait()永久阻塞(应用退出时恰好存在文档关闭任务即可触发;单测环境高概率复现)。f15ae39c为DocSheet::onBrowserPageChanged新增了可见性守卫,离屏单测环境中m_browser->isVisible()恒为 false,页码不回写,UT_DocSheet_onBrowserPageChanged_001断言失败。修复 / Fix
PageRenderThread::run()不再无条件重置m_quit(实例创建时默认即为 false),避免吞掉退出请求m_quit改为std::atomic<bool>,消除跨线程读写数据竞争isVisible与SheetSidebar::setCurrentPage桩,适配新守卫并避免单测触发渲染线程自测 / Test
TestDocSheet.UT_DocSheet_onBrowserPageChanged_001单跑通过且进程正常退出(修复前挂死)failures="0"Summary by Sourcery
Fix the render-thread shutdown race and adapt page-change testing to the browser visibility guard.
Bug Fixes:
Tests: