wallet: set a timeout if the db is busy.

This is recommended for litestream, which allows for easy async backup,
and harmless otherwise.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
Changelog-Changed: db: we now set a busy timeout to safely allow others to access sqlite3 db (e.g. litestream)
This commit is contained in:
Rusty Russell 2021-06-29 06:47:39 +09:30
parent c066378576
commit 5bf2b5c0ba

View file

@ -43,6 +43,11 @@ static bool db_sqlite3_setup(struct db *db)
}
db->conn = sql;
/* In case another writer (litestream?) grabs a lock, we don't
* want to return SQLITE_BUSY immediately (which will cause a
* fatal error): give it 5 seconds. */
sqlite3_busy_timeout(db->conn, 5000);
sqlite3_prepare_v2(db->conn, "PRAGMA foreign_keys = ON;", -1, &stmt, NULL);
err = sqlite3_step(stmt);
sqlite3_finalize(stmt);