fix tokio panic: use async lock in init_at/teardown for tokio-mutex modules

blocking_lock() panics when called from within the tokio async runtime.
Changed init_at() and teardown() to async fn with .lock().await for all
8 modules using tokio::sync::Mutex (library, reco, api_cache,
artist_vectors, musicbrainz, listenbrainz, offline_cache, lyrics).
Updated activate/deactivate_user_session to .await these calls.
This commit is contained in:
vicrodh committed 2026-02-05 23:47:48 -06:00
1 parent c237ccee50
commit 2dfb014a1e
9 files changed
+48 -48

No files matched your search

+4 -4
View File
@@ -25,18 +25,18 @@ pub struct LibraryState {
}
impl LibraryState {
pub fn init_at(&self, base_dir: &std::path::Path) -> Result<(), String> {
pub async fn init_at(&self, base_dir: &std::path::Path) -> Result<(), String> {
std::fs::create_dir_all(base_dir)
.map_err(|e| format!("Failed to create directory: {}", e))?;
let db_path = base_dir.join("library.db");
let db = LibraryDatabase::open(&db_path).map_err(|e| e.to_string())?;
let mut guard = self.db.blocking_lock();
let mut guard = self.db.lock().await;
*guard = Some(db);
Ok(())
}
pub fn teardown(&self) {
let mut guard = self.db.blocking_lock();
pub async fn teardown(&self) {
let mut guard = self.db.lock().await;
*guard = None;
}
}