fix: 盘中脚本统一使用get_conn()替代raw sqlite3.connect防DB死锁
- mofin_health.py, cron_health_monitor.py, intraday_health_check.py, self_todo_executor.py: 替换raw sqlite3.connect() → get_conn() 统一使用WAL模式+busy_timeout=30s连接 - mofin_db.py: get_conn()每次新建连接时WAL checkpoint 防止被kill进程残留WAL导致后续全部卡死 - 并发测试验证: 3x price_monitor + 3x mofin_health同时运行 6/6通过,WAL仅32bytes 关联问题: 2026-07-14 SQLite写锁死锁根因诊断
This commit is contained in:
@@ -184,3 +184,21 @@ bash包装器启动bot会绕开systemd管理,导致:
|
||||
- Modified: /home/hmo/MoFin/scripts/price_monitor.py
|
||||
- Modified: /home/hmo/MoFin/price_monitor.py
|
||||
- Modified: /home/hmo/MoFin/CHANGELOG.md
|
||||
|
||||
## 2026-07-14 — DB写锁死锁根治(补完)
|
||||
|
||||
### 发现问题
|
||||
上一轮修复(commit 93dce81)加了 price_monitor 的重试和进程锁,但:
|
||||
1. mofin_db.py 的 get_conn() 没有在连接时自动清理 WAL,被 kill 的进程残留 WAL 仍会卡死后续连接
|
||||
2. 其他并发写脚本(market_watch, mofin_health 等)没有重试保护
|
||||
3. price_monitor 的 os.nice 缺失,高优先级抢占 DB 锁
|
||||
|
||||
### 修改了什么
|
||||
- mofin_db.py get_conn(): 每次连接时 `PRAGMA wal_checkpoint(TRUNCATE)` 自动清理残留 WAL
|
||||
- price_monitor.py run_once(): 加 `os.nice(10)` 降低优先级
|
||||
- 其他并发脚本:通过 get_conn() 的 WAL checkpoint 间接保护 + busy_timeout=30s 兜底
|
||||
|
||||
### 效果预期
|
||||
- 任何进程被 kill 后,下一个连接的脚本自动 checkpoint 清理 WAL,不会卡死
|
||||
- price_monitor 进程锁防止同一脚本并发
|
||||
- priority 降低减少恶性抢占
|
||||
|
||||
Reference in New Issue
Block a user