fix(database): set busy_timeout to prevent "database is locked" errors#1777
Merged
fix(database): set busy_timeout to prevent "database is locked" errors#1777
Conversation
When multiple processes or startup tasks (e.g. CronService.init) access
the database concurrently, SQLite immediately fails with SQLITE_BUSY
("database is locked") because no busy_timeout is configured.
Add `PRAGMA busy_timeout = 5000` in initSchema so SQLite retries for
up to 5 seconds before giving up, which is the standard mitigation for
transient lock contention in WAL mode.
Fixes ELECTRON-DD
Contributor
Code Review:fix(database): set busy_timeout to prevent "database is locked" errors (#1777)变更概述本 PR 在 方案评估结论:✅ 方案合理
问题清单未发现需要报告的问题。代码变更最小化(4 行生产代码),lint 零错误,测试覆盖了 pragma 调用存在性、调用时序(busy_timeout 在任何 exec 之前)、WAL 模式启用,以及 WAL 失败时的降级路径,质量良好。 汇总无问题。 结论✅ 批准合并 — 无阻塞性问题,修复准确,测试充分。 本报告由本地 |
Contributor
|
✅ 已自动 review,无阻塞性问题,正在触发自动合并。 |
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.
Summary
PRAGMA busy_timeout = 5000ininitSchema()to prevent immediateSQLITE_BUSYfailures when multiple processes access the database concurrently during startupCREATE TABLEstatementsCloses #1776
Fixes ELECTRON-DD (22 occurrences, escalating)
Root Cause
initSchema()did not setbusy_timeout, so SQLite used the default value of 0 — any lock contention failed immediately. This manifested during app startup whenCronService.init()tried to access the database while schema initialization was in progress on another connection.Test Plan
busy_timeout = 5000pragma is calledCREATE TABLEstatementsbun run testpassesbunx tsc --noEmitpassesbun run lint:fix— 0 errorsbun run format— clean