Fix close-path SQLite lock by releasing write lock before exchange/sim ops.

Also enable WAL and busy_timeout on get_db so concurrent sim writes wait instead of failing immediately.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
dekun
2026-10-14 16:54:56 +08:00
parent 043b0aeded
commit d54bbdfcb3
2 changed files with 40 additions and 17 deletions
+7 -1
View File
@@ -1591,8 +1591,14 @@ def _purge_key_monitors_if_full_margin():
def get_db():
conn = sqlite3.connect(DB_PATH)
# timeout/busy_timeout: 并发写(平仓握锁 + sim 再开库)时等待而非立刻 database is locked
conn = sqlite3.connect(DB_PATH, timeout=30)
conn.row_factory = sqlite3.Row
try:
conn.execute("PRAGMA busy_timeout=30000")
conn.execute("PRAGMA journal_mode=WAL")
except Exception:
pass
return conn