Skip to content

fix(db): busy_timeout と WAL を設定し多重オープン時の SQLITE_BUSY を防ぐ (#1360)#1382

Merged
Kewton merged 2 commits into
developfrom
fix/1360-sqlite-busy-wal
Jul 17, 2026
Merged

fix(db): busy_timeout と WAL を設定し多重オープン時の SQLITE_BUSY を防ぐ (#1360)#1382
Kewton merged 2 commits into
developfrom
fix/1360-sqlite-busy-wal

Conversation

@Kewton

@Kewton Kewton commented Jul 17, 2026

Copy link
Copy Markdown
Owner

概要

Closes #1360

db-instance.ts の pragma が foreign_keys = ON のみで、busy_timeout(既定0=即エラー)も journal_mode=WAL も未設定だった。同一 DB を2プロセスが指すと即 SQLITE_BUSY になる。

変更

busy_timeoutjournal_mode=WAL を設定(最小限)。既存の foreign_keys・#1353 の将来版ガードの前後関係は不変。

品質(exit code 実測)

lint 0 / tsc 0 / CI=true test:unit 0 / build 0

🤖 Generated with Claude Code

getDbInstance() の接続 pragma は foreign_keys = ON のみで、busy_timeout
(既定 0 = ロック競合で即エラー)も journal_mode(既定のロールバック
ジャーナルは書き込み時に排他ロックを取る)も未設定だった。設定ミスで
2 つのサーバープロセスが同一 DB ファイルを指すと、書き込み競合が散発的な
500(SQLITE_BUSY)として現れ原因特定が難しかった。

接続直後・マイグレーション前(migration の書き込みにも効かせるため)に
journal_mode = WAL と busy_timeout = 5000 を追加。foreign_keys = ON
(#294、マイグレーション前必須)と #1353 のスキーマ検証後 singleton 代入の
前後関係は不変。多重オープンの検知・拒否は Issue 優先度が低いため見送り。

回帰テスト tests/unit/db/db-instance-pragmas.test.ts を追加(WAL は :memory:
では無視されるため実ファイル DB で検証)。

Issue 本文の記載について: 「対策コストが極小(pragma 2行)」とあるが、
db.pragma() は journal_mode と busy_timeout で 2 行、加えて既存の
foreign_keys で計 3 行になる(本修正では 2 行追加)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiJ2AKS69dJHVJvjExvG8b
@Kewton Kewton added the bug Something isn't working label Jul 17, 2026
@Kewton
Kewton merged commit b223d90 into develop Jul 17, 2026
9 checks passed
@Kewton
Kewton deleted the fix/1360-sqlite-busy-wal branch July 17, 2026 17:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant