Repository navigation
fix: 修复 6 个可确定性复现的可靠性缺陷(事件循环死锁 / 卡死状态机 / 配置丢失 / 假通知) - #518
Open
zzuu080603 wants to merge 5 commits into
Open
zzuu080603 wants to merge 5 commits into
zzuu080603 wants to merge 5 commits into
Conversation
added 5 commits
November 10, 2026 09:33
…deadlock add_recording/remove_recording/clear_all_recordings are coroutines that await disk writes while holding the lock. With a threading.Lock, another recording operation started during that await window blocks the entire event-loop thread — the holder can never resume to release the lock, so the whole app freezes (UI unresponsive, monitoring stops, only a process kill recovers). Verified with a repro: the old pattern deadlocks the loop deterministically while an asyncio.Lock completes the same workload.
An empty or JSON-corrupt user config (disk glitch, sync conflict, bad manual edit) evaluated falsy and was silently overwritten by the default template, destroying all user settings with no recovery. The file is now copied to user_settings.json.bak (with a warning log) before rebuilding from defaults; valid configs are untouched.
send_to_telegram returned success unconditionally: _async_post swallows
every exception into {'error': ...} and the Telegram API reports rejections
as HTTP 200 + {'ok': false}, so a wrong token/chat_id or dead proxy still
logged 'pushed successfully'. The response is now checked — {'ok': true}
is required, otherwise the failure (with description) is reported.
Two related stuck-state bugs that made a room unrecoverable until app restart: - start_ffmpeg/start_direct_download never unregistered the recorder on their exception paths (e.g. ffmpeg missing, spawn failure). The rec_id stayed in active_recorders forever, and since check_if_live skips rooms present in that dict — while replacing an entry also requires going through check_if_live — the room was permanently skipped. - start_recording's preparation block (filename/output dir/makedirs) ran before any try/except while start_update() had already flipped is_recording=True. Any failure there was silently swallowed by the fire-and-forget runner, leaving a fake 'recording' card with no file (as reported in ihmily#471) and blocking monitoring forever. The block now resets is_recording, marks the room as errored and unregisters. Also make remove_active_recorder unregister only itself (identity check), so a stale recorder exiting late cannot drop the registration of the newer recorder that replaced it.
DirectStreamDownloader swallowed every failure (expired URL / HTTP 403, DNS error, proxy failure) with a log line, and start_direct_download treated any finished task as success: empty/partial files produced a 'Direct Downloading Completed' push notification. The downloader now records the failure (self.error) and the caller marks the room as RECORDING_ERROR without the completion notification, then lets recheck_live_status retry with a fresh stream URL. Manual stops keep the previous behavior.
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)
🔍 描述(Description)
1. recordings 锁导致事件循环死锁
add_recording/remove_recording/clear_all_recordings是协程,持threading.Lock期间 await 写盘。此时另一录制操作尝试获取锁会阻塞整个事件循环线程,持锁方永远无法恢复释放锁 → 整个应用永久冻结(UI 无响应、监控停止、只能杀进程)。已用最小复现验证:同一段逻辑,旧写法确定性死锁(连 asyncio 的超时机制都失效),asyncio.Lock正常完成。批量删除房间时写盘窗口内再点任何房间操作即可触发。2. 录制器注册泄漏 → 房间永久跳过检测
start_ffmpeg/start_direct_download的异常路径(如 ffmpeg 不在 PATH、spawn 失败)从不注销active_recorders中的条目,而check_if_live一进门就跳过已注册的房间——唯一能删除/替换条目的路径恰恰要经过被跳过的检测,形成闭环,只能重启恢复。3. start_recording 前置段异常 → 假录制(#471 同族)
start_update()已置is_recording=True后,start_recording的准备段(文件名/输出目录/makedirs)不在任何 try 内;该协程经 fire-and-forget 调度,异常被完全吞掉 → 卡片永远"录制中"但无文件,监控永久跳过。现在异常会复位标志、置错误状态并注销。4. 损坏的用户配置被默认配置静默覆盖
user_settings.json 为空或 JSON 损坏(磁盘故障/网盘同步冲突/手动编辑出错)时,
init_user_config直接用默认模板整体覆盖,所有个性化设置不可逆丢失。现在先备份到user_settings.json.bak(带警告日志)再重建。5. Telegram 推送失败被无条件上报为成功
_async_post吞掉所有异常返回{'error': ...},且 Telegram API 以 HTTP 200 +{'ok': false}报告拒绝——代码从不检查,send_to_telegram恒返回成功,"Push Telegram message successfully" 误导排障。现在要求{'ok': True}才算成功,失败时带 description 上报。6. 直连下载失败被当作"录制完成"
DirectStreamDownloader吞掉全部失败(链接过期 403/DNS/代理),start_direct_download用task.done()判断结束,无法区分成败 → 空文件/残缺文件触发"下载完成"推送。现在下载器记录self.error,调用方在失败时置RECORDING_ERROR、不发完成通知,并经recheck_live_status自动重试;手动停止行为不变。另外
remove_active_recorder增加身份校验(is self),防止迟退出的旧录制器误删已替换它的新录制器注册。📝 类型(Type of Change)
🏗️ 测试(Testing)
对每项修复编写了行为级验证脚本(加载项目真实源码,stub 第三方依赖),红→绿 双向验证:
ruff check与语法编译全部通过复现方式(均为确定性,无需真实直播平台):并发调用带锁方法、让
create_subprocess_exec抛异常、输出目录指向不可创建路径、写入损坏 JSON、mock Telegram 响应{'ok': false}、mock 下载 HTTP 403。📋 检查清单(Checklist)
Fixes #471
Helps #475