Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions api/internal/db/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ func Open(ctx context.Context, driver, dsn string) (*Store, error) {
// Add a busy timeout to the DSN if not already present, so concurrent
// processes (e.g., API and bootstrap-admin) waiting for locks don't fail immediately.
dsn = withSQLiteBusyTimeout(dsn)
// Take the write lock when a read-write transaction begins. A deferred
// transaction that reads first and writes later cannot wait in WAL mode:
// if another process wrote in between, SQLite returns SQLITE_BUSY at once
// and skips busy_timeout (seen with bootstrap-admin next to a live API).
// Read-only transactions stay deferred. withSQLiteBusyTimeout always
// leaves a query string, and the driver reads the first _txlock value,
// so a _txlock already in the configured DSN still wins.
dsn += "&_txlock=immediate"

db, err := sql.Open("sqlite", dsn)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/1028-sqlite-bootstrap-admin-lock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# bootstrap-admin no longer fails with "database is locked" on SQLite

Running `bootstrap-admin` while the API is serving could fail at once with
`database is locked (SQLITE_BUSY)`, even with the busy timeout set. SQLite
read-write transactions now take the write lock when they begin, so they wait
for the lock instead of failing. No action is needed. [PR #1028](https://github.com/GameplanePanel/Gameplane/pull/1028)
Loading