From 5bf2b5c0ba8c2b531b28633107a4358c5060ff1b Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Tue, 29 Jun 2021 06:47:39 +0930 Subject: [PATCH] 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 Changelog-Changed: db: we now set a busy timeout to safely allow others to access sqlite3 db (e.g. litestream) --- wallet/db_sqlite3.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wallet/db_sqlite3.c b/wallet/db_sqlite3.c index ba90e4d5f..282e2b6a0 100644 --- a/wallet/db_sqlite3.c +++ b/wallet/db_sqlite3.c @@ -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);