Skip to content

Commit

Permalink
sqlite: set busy timeout to 100s
Browse files Browse the repository at this point in the history
Only one process can write to the sqlite db at the same time, if another
process tries to use it at that time it fails and a database is locked
error is returned. If this happens sqlite should keep retrying until it
can write. To do that we can just set the _busy_timeout option. A 100s
timeout should be enough even on slower systems but not to much in case
there is a deadlock so it still returns in a reasonable time.

[NO NEW TESTS NEEDED] I think we strongly need to consider some form of
parallel stress testing to catch bugs like this.

Fixes containers#20809

Signed-off-by: Paul Holzinger <[email protected]>
  • Loading branch information
Luap99 committed Nov 29, 2023
1 parent 06c41b6 commit 5b3d82f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libpod/sqlite_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,17 @@ const (
sqliteOptionForeignKeys = "&_foreign_keys=1"
// Make sure that transactions happen exclusively.
sqliteOptionTXLock = "&_txlock=exclusive"
// Make sure busy timeout is set to high value to keep retying when the db is locked.
// Timeout is in ms, so set it to 100s to have enough time to retry the operations.
sqliteOptionBusyTimeout = "&_busy_timeout=100000"

// Assembled sqlite options used when opening the database.
sqliteOptions = "db.sql?" +
sqliteOptionLocation +
sqliteOptionSynchronous +
sqliteOptionForeignKeys +
sqliteOptionTXLock
sqliteOptionTXLock +
sqliteOptionBusyTimeout
)

// NewSqliteState creates a new SQLite-backed state database.
Expand Down

0 comments on commit 5b3d82f

Please sign in to comment.