Repository navigation
fix(download): 暂停后不再落盘正在读取的分块 - #85
Open
std-external wants to merge 1 commit into
Open
std-external wants to merge 1 commit into
std-external wants to merge 1 commit into
Conversation
下载线程只在每次 read 之前检查暂停标志,而 read 本身无法中断:暂停时 正在读取的那一块读完后仍会被写入文件并上报进度,8 线程分段下载时会 ×8,用户看到的就是「按了暂停还在下载」。 现在读到的一块先留在内存里,等恢复后再落盘,暂停后文件大小与进度会 立刻停住;同时多线程下载在暂停期间不再发起 HEAD / Range 探测请求。
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.
问题
在「下载任务」页面点某一条任务的「暂停」之后,进度数字 / 文件大小还会继续涨,看起来暂停是假的。
原因
src-tauri/src/ureq.rs里暂停标志只在每次read()之前检查,而正在阻塞的read()无法被中断:按下暂停时正在读取的那一块(最多 256 KiB)读完后仍然会落盘并计入进度;多线程分段下载有 8 条连接,同一时刻最多会多写约 2 MiB。
download_single和download_range_part都是这个结构。修复
download_multi_thread开头也等一次暂停,暂停期间不再为新任务发起 HEAD / Range 探测请求。只改
src-tauri/src/ureq.rs,不动下载协议、重试与断点续传逻辑。验证
新增两个回归测试(本地 TCP 服务器 + 真实
ureq下载路径):pause_stops_writes_until_resumed:单连接下载到 4 MiB 后暂停,断言文件不再增长,恢复后仍能完整下载。multi_thread_pause_stops_writes_until_resumed:8 线程分段下载,服务器每个分段只发 64 KiB 前缀后卡住,暂停后放行剩余数据,断言进度计数器不再增长。修复前
cargo test --lib pause_ -- --test-threads=1:修复后:
完整
cargo test --lib:109 passed / 0 failed;cargo fmt --all -- --check通过(nightly toolchain)。说明
read()返回才会生效(当前没有 read 超时,PR fix(download): 下载链路走 ureq 自带的环境代理 + 补上读写超时 #84 在补);本 PR 没有改这一点。stores/download.ts:133忽略了set_mod_download_paused的返回值,所以后端说「没找到这个任务」(例如下载已经结束)时界面依然会显示「已暂停」;这条没有在本 PR 里改。来源:社区群里的用户反馈(1.2.1)「下载任务里面的暂停是假的吧」。