Repository navigation
fix: 修复 3 个高危运行时缺陷(检测循环静默死亡 / 直连下载失败误报成功 / 退出截断转码产物) - #521
Open
zzuu080603 wants to merge 3 commits into
Open
zzuu080603 wants to merge 3 commits into
zzuu080603 wants to merge 3 commits into
Conversation
added 3 commits
November 10, 2026 17:41
…invalid shutil.disk_usage raises FileNotFoundError when the configured live_save_path does not exist (network drive offline, typo, unmounted disk), which killed the periodic_check task silently - live detection stopped with no UI hint. - wrap the periodic_check loop body so one failing iteration only logs and retries on the next interval - harden check_free_space: on OSError inspect the default recordings dir as a fallback, and skip the check (instead of raising) when both fail
… success A non-2xx response (403/404/dead link) made _download_stream return cleanly, so start_direct_download reported 'Direct Downloading Completed' and the task went back to MONITORING - a failed pull looked like a finished recording and could even fire a stream-end push. - DirectStreamDownloader gains a failed flag, set on non-2xx responses and on I/O errors (manual cancel stays clean) - start_direct_download routes failed pulls to _handle_recording_error (RECORDING_ERROR status + snack) instead of _handle_recording_finished
converts_mp4 and custom_script_execute hand their work to BackgroundService (a non-daemon thread) when the app is closing, but both exit paths called os._exit(0) after a bounded wait, which kills the process without running any thread - queued transcodes died mid-write and left truncated mp4 files. - add _wait_background_service(): poll the queue for up to 120s (progress log every 10s) before os._exit, covering both the with-recordings and the direct exit paths - past the deadline the remaining tasks are abandoned explicitly with an error log instead of dying silently
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.
📜 标题(Title)
os._exit(0)硬杀后台转码任务留下截断的 mp4。🔍 描述(Description)
三个缺陷相互独立,均为确定性可复现,各自对应一个独立 commit:
1. 无效保存目录杀死周期检测循环(
7a893e9)periodic_check的while True中await self.check_free_space()无异常保护。当live_save_path指向不存在的目录(网络盘掉线/路径笔误/磁盘未挂载)时,shutil.disk_usage抛FileNotFoundError,整个检测任务静默死亡——此后开播检测、磁盘恢复检测全部停摆,UI 无任何提示,录制功能“看似正常但永不触发”。try/except,单轮失败仅记日志并在下个间隔重试check_free_space硬化:OSError时回退默认录制目录重查,两处都失败则跳过本轮(不向上抛)2. 直连下载失败伪装成录制完成(
4c5db59)_download_stream收到非 2xx(403/404/断链)时直接return,无异常无标志;外层start_direct_download只看download_task.done()即走_handle_recording_finished,日志打出 "Direct Downloading Completed"。失败的拉流对用户呈现为正常结束,还可能触发“直播结束”推送。DirectStreamDownloader新增failed标志:非 2xx 与 I/O 异常置位,手动取消保持干净failed and not should_stop分流至_handle_recording_error(RECORDING_ERROR状态 + 错误提示)3. 退出时后台转码被硬杀(
19820ba)关闭应用时
converts_mp4/custom_script_execute将任务移交BackgroundService(非 daemon 线程),但两条退出路径在有限等待后调用os._exit(0)——它不等待任何线程(包括非 daemon),队列中的转码/脚本任务被拦腰杀死,留下截断的 mp4。_wait_background_service():os._exit前轮询排空队列,上限 120s,每 10s 打进度日志BackgroundService)📝 类型(Type of Change)
🏗️ 测试(Testing)
独立 venv(按 requirements.txt 安装依赖 + imageio-ffmpeg 提供真实 ffmpeg)导入生产代码冒烟,2/2 通过:
live_save_path指向不存在路径 + 2s 轮询间隔,日志按间隔出现 5 条Cannot inspect disk space(循环存活且持续重试),9s 内完成 5 次迭代,recording_enabled经回退目录保持为 True(修复前第一条异常后循环即死)converts_mp4(recording_enabled=False模拟关闭)→BackgroundService→ ffmpeg remux 2s ts →_wait_background_service():mp4 产物 Duration 2.04s、双流完整、原件移入original/(converts_success=True的判据);负例(30s 慢任务 + 3s 预算)精确 3.0s 返回并打出放弃日志py_compile与ruff check(4 个改动文件)均通过📋 检查清单(Checklist)
三个缺陷来自代码审查(无对应 issue);修复均保持向后兼容,默认行为不变。