Skip to content

Commit 73e0441

Browse files
fix(tauri): spawn sidecar after database init, not before
Sidecar spawn raced Database::new()'s creation of mt.db: on a fresh install with no pre-existing db file, the sidecar's own SQLite open would fail before Rust finished creating it, and the sidecar died before the health probe could reach it. Move the spawn after Database::new() returns so the db file always exists first.
1 parent 7f96d4a commit 73e0441

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

‎crates/mt-tauri/src/lib.rs‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -604,18 +604,21 @@ pub fn run() {
604604
std::fs::create_dir_all(parent).ok();
605605
}
606606

607-
if let Some(runtime_dir) = db_path.parent() {
608-
sidecar::spawn(app, &db_path, runtime_dir);
609-
} else {
610-
error!("sidecar not started: could not determine app data directory");
611-
}
612-
613607
let database = db::Database::new(&db_path)
614608
.expect("Failed to initialize database");
615609
let database_for_watcher = database.clone();
616610
app.manage(database);
617611
info!(path = %db_path.display(), "Database initialized");
618612

613+
// Sidecar spawn must come after Database::new() creates and migrates
614+
// mt.db -- otherwise the sidecar races Rust's own db creation and its
615+
// SQLite open fails on every fresh install with no pre-existing db file.
616+
if let Some(runtime_dir) = db_path.parent() {
617+
sidecar::spawn(app, &db_path, runtime_dir);
618+
} else {
619+
error!("sidecar not started: could not determine app data directory");
620+
}
621+
619622
// Initialize artwork cache (Rust LRU cache)
620623
let artwork_cache = scanner::artwork_cache::ArtworkCache::with_capacity(50);
621624
app.manage(artwork_cache);

0 commit comments

Comments
 (0)