Repository navigation
fix: add memory check before opening files - #704
Draft
pppanghu77 wants to merge 1 commit into
Draft
pppanghu77 wants to merge 1 commit into
pppanghu77 wants to merge 1 commit into
Conversation
1. Root cause: Window::addTab() and EditWrapper::openFile() load entire file content into memory without checking available RAM, causing OOM-kill when opening multiple large files 2. Fix: call existing Utils::isMemorySufficientForOperation() with RawOperation type before file loading in both entry points, show warning and abort if memory is insufficient 3. Impact: files are blocked from opening when memory is low instead of crashing; no behavior change when memory is sufficient Log: Prevent crash when opening large files with insufficient memory Influence: 1. Test opening large files under low memory conditions 2. Verify normal file opening is not affected 3. Test opening multiple files simultaneously fix: 打开文件前增加内存检查 1. 根因:Window::addTab() 和 EditWrapper::openFile() 在加载文件时 将整个文件内容读入内存,未检查可用内存,打开多个大文件时触发 OOM-kill 崩溃 2. 方案:在两个入口点加载文件前调用已有的 Utils::isMemorySufficientForOperation()(RawOperation 类型), 内存不足时显示警告并中止打开 3. 影响:内存不足时阻止文件打开而非崩溃;内存充足时行为不变 Log: 打开大文件时内存不足改为提示而非崩溃 Influence: 1. 测试低内存条件下打开大文件 2. 验证正常文件打开不受影响 3. 测试同时打开多个文件 PMS: BUG-111510
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: pppanghu77 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 GuidePrevents OOM-related crashes when opening large files by reusing the existing memory check at both the tab-level and editor-level open paths, warning users and returning early when available memory is insufficient while leaving normal opens unchanged. Sequence diagram for memory-checked file openingsequenceDiagram
actor User
participant Window
participant Utils
participant EditWrapper
participant FileLoadThread
participant MessageManager
User->>Window: addTab(filepath, activeTab)
Window->>Utils: isMemorySufficientForOperation(RawOperation, fileSize, 0)
alt memory insufficient
Window->>MessageManager: sendMessage(...)
Window-->>User: Open aborted with warning
else memory sufficient
Window->>EditWrapper: openFile(filepath, ...)
EditWrapper->>Utils: isMemorySufficientForOperation(RawOperation, fileSize, 0)
alt memory insufficient
EditWrapper->>MessageManager: sendMessage(...)
EditWrapper-->>User: Open aborted with warning
else memory sufficient
EditWrapper->>FileLoadThread: FileLoadThread(filepath)
FileLoadThread-->>User: File loading proceeds
end
end
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
pppanghu77
marked this pull request as draft
October 29, 2026 19:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root Cause Analysis
deepin-editor crashes (OOM-kill) when opening multiple large files. The root cause is that
Window::addTab()andEditWrapper::openFile()load entire file content into memory (QByteArray + QTextDocument UTF-16 dual storage, ~5.68x memory amplification) without any pre-check on available system memory. When multiple large files are opened across tabs, memory consumption exceeds system limits, triggering the OOM-killer.Fix
Added a pre-memory check using the existing
Utils::isMemorySufficientForOperation()function (withRawOperationtype) in bothWindow::addTab()(after readability check, beforeStartManager::checkPath()) andEditWrapper::openFile()(before creatingFileLoadThread). When memory is insufficient, a warning message is shown and the file open is aborted instead of crashing.Change Safety Assessment
Code Safety
Utils::isMemorySufficientForOperation()already used in copy/paste paths — consistent with existing patternsBusiness Impact Scope
addTab()(primary entry) andopenFile()(safety net for other callers likeaddTemFileTab)Verification Suggestion
Test opening large files under low memory conditions to verify the warning appears and no crash occurs. Verify normal file opening is unaffected.
根因分析
deepin-editor 打开多个大文件时崩溃(OOM-kill)。根因是
Window::addTab()和EditWrapper::openFile()在加载文件时将整个文件内容读入内存(QByteArray + QTextDocument UTF-16 双份存储,约 5.68 倍内存放大),未做可用内存前置检查。多标签页叠加打开大文件时,内存消耗超过系统限制,触发 OOM-killer。修复方案
在
Window::addTab()(可读性检查之后、StartManager::checkPath()之前)和EditWrapper::openFile()(创建FileLoadThread之前)两个入口点添加前置内存检查,复用已有的Utils::isMemorySufficientForOperation()函数(RawOperation类型)。内存不足时显示警告提示并中止打开,而非崩溃。改动安全评估
代码安全评估
Utils::isMemorySufficientForOperation(),与复制/粘贴路径的内存检查模式一致业务影响范围
addTab()(主入口)和openFile()(覆盖addTemFileTab等其他调用方)验证建议
测试低内存条件下打开大文件,验证提示出现且不崩溃。验证正常文件打开不受影响。
Summary by Sourcery
Prevent out-of-memory crashes by checking available memory before loading files.
Bug Fixes:
Enhancements: