From 1b70fc237274b16cca779fce7f084268d3b3b915 Mon Sep 17 00:00:00 2001 From: jonyoi Date: Mon, 20 Jul 2026 15:02:26 -0400 Subject: [PATCH] feat: add busy_timeout to verify! method --- lib/litestream.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/litestream.rb b/lib/litestream.rb index 159faa9..1058b44 100644 --- a/lib/litestream.rb +++ b/lib/litestream.rb @@ -37,8 +37,10 @@ def initialize mattr_accessor :base_controller_class, default: "::ApplicationController" class << self - def verify!(database_path, replication_sleep: 10) + def verify!(database_path, replication_sleep: 10, busy_timeout: 5000) database = SQLite3::Database.new(database_path) + # Apply the busy_timeout to handle concurrent write locks gracefully + database.busy_timeout = busy_timeout database.execute("CREATE TABLE IF NOT EXISTS _litestream_verification (id INTEGER PRIMARY KEY, uuid BLOB)") sentinel = SecureRandom.uuid database.execute("INSERT INTO _litestream_verification (uuid) VALUES (?)", [sentinel]) @@ -49,6 +51,7 @@ def verify!(database_path, replication_sleep: 10) Litestream::Commands.restore(database_path, **{"-o" => backup_path}) backup = SQLite3::Database.new(backup_path) + backup.busy_timeout = busy_timeout result = backup.execute("SELECT 1 FROM _litestream_verification WHERE uuid = ? LIMIT 1", sentinel) # => [[1]] || [] raise VerificationFailure, "Verification failed for `#{database_path}`" if result.empty?