fix(db): busy_timeout と WAL を設定し多重オープン時の SQLITE_BUSY を防ぐ (#1360)#1382
Merged
Conversation
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
…sy-wal # Conflicts: # CHANGELOG.md
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.
概要
Closes #1360
db-instance.tsの pragma がforeign_keys = ONのみで、busy_timeout(既定0=即エラー)もjournal_mode=WALも未設定だった。同一 DB を2プロセスが指すと即SQLITE_BUSYになる。変更
busy_timeoutとjournal_mode=WALを設定(最小限)。既存の foreign_keys・#1353 の将来版ガードの前後関係は不変。品質(exit code 実測)
lint 0 / tsc 0 /
CI=truetest:unit 0 / build 0🤖 Generated with Claude Code