diff --git a/libpod/sqlite_state.go b/libpod/sqlite_state.go index 912570fa7b..f51cdc3d7a 100644 --- a/libpod/sqlite_state.go +++ b/libpod/sqlite_state.go @@ -39,17 +39,13 @@ 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 retrying 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 + - sqliteOptionBusyTimeout + sqliteOptionTXLock ) // NewSqliteState creates a new SQLite-backed state database. @@ -71,7 +67,18 @@ func NewSqliteState(runtime *Runtime) (_ State, defErr error) { return nil, fmt.Errorf("creating root directory: %w", err) } - conn, err := sql.Open("sqlite3", filepath.Join(basePath, sqliteOptions)) + // Make sure busy timeout is set to high value to keep retrying when the db is locked. + // Timeout is in ms, so set it to 100s to have enough time to retry the operations. + // Some users might want to experiment with different timeout values (#23236) + // DO NOT DOCUMENT or recommend PODMAN_SQLITE_BUSY_TIMEOUT outside of testing. + busyTimeout := "100000" + if env, ok := os.LookupEnv("PODMAN_SQLITE_BUSY_TIMEOUT"); ok { + logrus.Debugf("PODMAN_SQLITE_BUSY_TIMEOUT is set to %s", env) + busyTimeout = env + } + sqliteOptionBusyTimeout := "&_busy_timeout=" + busyTimeout + + conn, err := sql.Open("sqlite3", filepath.Join(basePath, sqliteOptions+sqliteOptionBusyTimeout)) if err != nil { return nil, fmt.Errorf("initializing sqlite database: %w", err) }