Repository navigation
fix: skip fsync on network filesystems to prevent UI freeze - #451
dengzhongyuan365-dev wants to merge 1 commit into
Conversation
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: dengzhongyuan365-dev 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 |
Reviewer's GuideImplementationDetect network filesystems and skip synchronous fsync during saves there while retaining fsync for local filesystems.
TestsAdd unit tests for network-filesystem detection on GVFS and local paths.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="3rdparty/deepin-pdfium/src/dpdfdoc.cpp" line_range="325-326" />
<code_context>
newFile.flush(); // Flush user buffer to kernel buffer
- fsync(newFile.handle()); // Sync kernel buffer to disk
+ if (!isOnNetworkFileSystem(newFile.handle()))
+ fsync(newFile.handle()); // Sync kernel buffer to disk (skip on network FS)
newFile.close();
</code_context>
<issue_to_address>
**Saved changes disappear after a crash**
When the network filesystem has acknowledged writes into a cache but has not committed them to stable storage, `save()` and `saveAs()` skip `fsync()` and can return success before the writes are durable; `save()` then removes its backup, so a client or server crash can lose the latest PDF changes.
Ensure the replacement reaches stable storage before reporting success or removing the backup, using a durability mechanism that works for network filesystems.
Also at `3rdparty/deepin-pdfium/src/dpdfdoc.cpp:353-354`.
</issue_to_address>
### Comment 2
<location path="3rdparty/deepin-pdfium/src/dpdfdoc.cpp" line_range="31" />
<code_context>
+static bool isOnNetworkFileSystem(int fd)
+{
+ struct statfs buf;
+ if (fstatfs(fd, &buf) != 0)
+ return false;
+
</code_context>
<issue_to_address>
**SMB saves still freeze the UI**
When an SMB server is slow or unresponsive during the filesystem-stat lookup, `isOnNetworkFileSystem()` calls synchronous `fstatfs()` before the guarded `fsync()`, so the save blocks the caller and freezes the UI.
Avoid performing a potentially blocking remote `fstatfs()` lookup on the save thread.
</issue_to_address>
### Comment 3
<location path="3rdparty/deepin-pdfium/src/dpdfdoc.cpp" line_range="34-36" />
<code_context>
+ if (fstatfs(fd, &buf) != 0)
+ return false;
+
+ return buf.f_type == SMB_SUPER_MAGIC
+ || buf.f_type == SMB2_SUPER_MAGIC
+ || buf.f_type == 0xFF534D42; // CIFS_MAGIC_NUMBER (not in userspace headers)
+}
</code_context>
<issue_to_address>
**Network saves still freeze the UI**
When a document is saved on NFS or another network filesystem not identified by the SMB/CIFS magic values, or `fstatfs()` fails, `isOnNetworkFileSystem()` returns false, so `save()` and `saveAs()` still call synchronous `fsync()` and can freeze the UI.
Handle unrecognized and unclassifiable network filesystems so their saves do not perform a blocking synchronous `fsync()` on the UI thread.
Also at `3rdparty/deepin-pdfium/src/dpdfdoc.cpp:31-33`.
</issue_to_address>| if (!isOnNetworkFileSystem(newFile.handle())) | ||
| fsync(newFile.handle()); // Sync kernel buffer to disk (skip on network FS) |
There was a problem hiding this comment.
🟡 Medium · Saved changes disappear after a crash
When the network filesystem has acknowledged writes into a cache but has not committed them to stable storage, save() and saveAs() skip fsync() and can return success before the writes are durable; save() then removes its backup, so a client or server crash can lose the latest PDF changes.
Ensure the replacement reaches stable storage before reporting success or removing the backup, using a durability mechanism that works for network filesystems.
Also at 3rdparty/deepin-pdfium/src/dpdfdoc.cpp:353-354.
Prompt for AI agents
In `3rdparty/deepin-pdfium/src/dpdfdoc.cpp` at lines 325-326:
**Saved changes disappear after a crash**
When the network filesystem has acknowledged writes into a cache but has not committed them to stable storage, `save()` and `saveAs()` skip `fsync()` and can return success before the writes are durable; `save()` then removes its backup, so a client or server crash can lose the latest PDF changes.
Ensure the replacement reaches stable storage before reporting success or removing the backup, using a durability mechanism that works for network filesystems.
Also at `3rdparty/deepin-pdfium/src/dpdfdoc.cpp:353-354`.| static bool isOnNetworkFileSystem(int fd) | ||
| { | ||
| struct statfs buf; | ||
| if (fstatfs(fd, &buf) != 0) |
There was a problem hiding this comment.
🟡 Medium · SMB saves still freeze the UI
When an SMB server is slow or unresponsive during the filesystem-stat lookup, isOnNetworkFileSystem() calls synchronous fstatfs() before the guarded fsync(), so the save blocks the caller and freezes the UI.
Avoid performing a potentially blocking remote fstatfs() lookup on the save thread.
Prompt for AI agents
In `3rdparty/deepin-pdfium/src/dpdfdoc.cpp` at line 31:
**SMB saves still freeze the UI**
When an SMB server is slow or unresponsive during the filesystem-stat lookup, `isOnNetworkFileSystem()` calls synchronous `fstatfs()` before the guarded `fsync()`, so the save blocks the caller and freezes the UI.
Avoid performing a potentially blocking remote `fstatfs()` lookup on the save thread.| return buf.f_type == SMB_SUPER_MAGIC | ||
| || buf.f_type == SMB2_SUPER_MAGIC | ||
| || buf.f_type == 0xFF534D42; // CIFS_MAGIC_NUMBER (not in userspace headers) |
There was a problem hiding this comment.
🟡 Medium · Network saves still freeze the UI
When a document is saved on NFS or another network filesystem not identified by the SMB/CIFS magic values, or fstatfs() fails, isOnNetworkFileSystem() returns false, so save() and saveAs() still call synchronous fsync() and can freeze the UI.
Handle unrecognized and unclassifiable network filesystems so their saves do not perform a blocking synchronous fsync() on the UI thread.
Also at 3rdparty/deepin-pdfium/src/dpdfdoc.cpp:31-33.
Prompt for AI agents
In `3rdparty/deepin-pdfium/src/dpdfdoc.cpp` at lines 34-36:
**Network saves still freeze the UI**
When a document is saved on NFS or another network filesystem not identified by the SMB/CIFS magic values, or `fstatfs()` fails, `isOnNetworkFileSystem()` returns false, so `save()` and `saveAs()` still call synchronous `fsync()` and can freeze the UI.
Handle unrecognized and unclassifiable network filesystems so their saves do not perform a blocking synchronous `fsync()` on the UI thread.
Also at `3rdparty/deepin-pdfium/src/dpdfdoc.cpp:31-33`.bd54cb7 to
7954676
Compare
|
TAG Bot TAG: 6.5.70 |
7954676 to
dcfdebe
Compare
1. Root cause: DPdfDoc::save() and saveAs() call fsync() on the main thread for files on SMB/CIFS network mounts, blocking the Qt event loop for seconds while waiting for remote disk sync 2. Fix: add isNetworkFileSystem() helper using QStorageInfo to detect cifs/smb/fuse.gvfs paths, skip fsync for network paths while keeping flush() for userspace-to-kernel buffer transfer 3. Impact: local disk save behavior unchanged (fsync still called); network path save no longer blocks UI; temp-file-then-rename preserves atomicity and backup recovery Log: 修复SMB网络路径保存PDF时文档查看器卡死问题 Influence: 1. Test saving PDF with bookmarks/annotations on local disk 2. Test saving PDF on SMB mount and verify no UI freeze 3. Test saveAs to SMB path 4. Test save failure recovery on network disconnect fix: 跳过网络文件系统路径的fsync以防止界面卡死 1. 根因:DPdfDoc::save()和saveAs()在主线程对SMB/CIFS网络挂载 路径的文件调用fsync(),等待远端刷盘时阻塞Qt事件循环数秒 2. 方案:新增isNetworkFileSystem()辅助函数,使用QStorageInfo检测 cifs/smb/fuse.gvfs路径,网络路径跳过fsync,保留flush()完成 用户态到内核态的缓冲刷入 3. 影响:本地磁盘保存行为不变(仍执行fsync);网络路径保存不再 阻塞界面;temp-file-then-rename保证原子性和备份恢复 Log: 修复SMB网络路径保存PDF时文档查看器卡死问题 Influence: 1. 测试本地磁盘上保存带书签/注释的PDF 2. 测试SMB挂载路径保存PDF,验证不再卡死 3. 测试另存为到SMB路径 4. 测试网络断开时保存失败的恢复 PMS: BUG-380239
dcfdebe to
927baf3
Compare
Root Cause Analysis
DPdfDoc::save()andDPdfDoc::saveAs()callfsync()synchronously on the Qt main thread. On local filesystemsfsyncis negligible (~3ms measured), but on SMB/CIFS mountsfsynctriggers a network round-trip to the SMB server (SMB SET_FILE_INFO + wait for server flush confirmation), blocking the event loop for seconds or longer, causing the document viewer UI to freeze completely. The save is triggered by a 100ms auto-save timer after annotation changes and on document close.Key evidence: blocking point at
3rdparty/deepin-pdfium/src/dpdfdoc.cpp:293(save) and:353(saveAs); reproduction with FUSE-simulated slow fsync showed ~3.2s UI freeze before fix, ~3ms after skipping fsync.Fix
Added a file-scope static helper
isOnNetworkFileSystem(int fd)usingfstatfs()to detect SMB/CIFS filesystem types (SMB_SUPER_MAGIC,SMB2_SUPER_MAGIC,CIFS_MAGIC_NUMBER). Bothsave()andsaveAs()now skipfsync()on network filesystems while keeping it on local filesystems to preserve crash durability (BUG-88915/BUG-351271).Change Safety Assessment
Code Safety
isOnNetworkFileSystemis a file-scope static function with no external callers;change-safety-raw.jsonreference list is empty (reference_count=0)fsyncon local FS; BUG-351271 (SMB save failure) rename-to-backup mode unchanged; BUG-370563 (NAME_MAX overflow) UUID-only backup naming unchangedBusiness Impact Scope
DPdfDoc::save()(dpdfdoc.cpp:241),DPdfDoc::saveAs()(dpdfdoc.cpp:330)Verification Suggestion
根因分析
DPdfDoc::save()和DPdfDoc::saveAs()在 Qt 主线程同步调用fsync()。在本地文件系统上fsync耗时可忽略(实测 ~3ms),但在 SMB/CIFS 网络挂载上fsync触发到 SMB 服务器的网络往返(SMB SET_FILE_INFO + 等待服务器确认刷盘),阻塞事件循环数秒甚至更久,导致文档查看器界面完全冻结。保存动作在添加注释后 100ms 自动保存定时器触发及关闭文档时触发。关键证据:阻塞点位于
3rdparty/deepin-pdfium/src/dpdfdoc.cpp:293(save)和:353(saveAs);复现实验用 FUSE 模拟慢速 fsync,修复前 ~3.2s UI 冻结,跳过 fsync 后 ~3ms。修复方案
新增 file-scope static 函数
isOnNetworkFileSystem(int fd),使用fstatfs()检测 SMB/CIFS 文件系统类型(SMB_SUPER_MAGIC、SMB2_SUPER_MAGIC、CIFS_MAGIC_NUMBER),在save()和saveAs()两处fsync调用前判断:网络文件系统跳过fsync,本地文件系统保留fsync以维持崩溃持久性(BUG-88915/BUG-351271)。改动安全评估
代码安全评估
isOnNetworkFileSystem为 file-scope static 函数,无外部调用者;change-safety-raw.json引用列表为空(reference_count=0)fsync保留;BUG-351271(SMB 保存失败)rename-to-backup 模式不变;BUG-370563(NAME_MAX 溢出)UUID-only 命名不变业务影响范围
DPdfDoc::save()(dpdfdoc.cpp:241)、DPdfDoc::saveAs()(dpdfdoc.cpp:330)验证建议
Summary by Sourcery
Avoid UI freezes during PDF saves by skipping fsync on network filesystems while retaining local filesystem durability.
Bug Fixes:
Enhancements:
Tests: