From 38dda8c44c7adb06cf983c5b2fda97c1c98a8441 Mon Sep 17 00:00:00 2001 From: vikingowl Date: Thu, 26 Mar 2026 17:59:32 +0100 Subject: [PATCH] fix: watcher startup grace period, defensive runtime drop on reload --- crates/owlry-core/src/plugins/watcher.rs | 8 ++++++++ crates/owlry-core/src/providers/mod.rs | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/owlry-core/src/plugins/watcher.rs b/crates/owlry-core/src/plugins/watcher.rs index 15ebadb..f3bb346 100644 --- a/crates/owlry-core/src/plugins/watcher.rs +++ b/crates/owlry-core/src/plugins/watcher.rs @@ -69,9 +69,17 @@ fn watch_loop( info!("Watching {} for plugin changes", plugins_dir.display()); + // Skip events during initial startup grace period (watcher setup triggers events) + let startup = std::time::Instant::now(); + let grace_period = Duration::from_secs(2); + loop { match rx.recv() { Ok(Ok(events)) => { + if startup.elapsed() < grace_period { + continue; + } + let has_relevant_change = events.iter().any(|e| { matches!( e.kind, diff --git a/crates/owlry-core/src/providers/mod.rs b/crates/owlry-core/src/providers/mod.rs index 11dc66e..fd607ec 100644 --- a/crates/owlry-core/src/providers/mod.rs +++ b/crates/owlry-core/src/providers/mod.rs @@ -292,8 +292,11 @@ impl ProviderManager { !self.runtime_type_ids.contains(&type_str) }); - // Drop old runtimes - self.runtimes.clear(); + // Drop old runtimes (catch panics from runtime cleanup) + let old_runtimes = std::mem::take(&mut self.runtimes); + drop(std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| { + drop(old_runtimes); + }))); self.runtime_type_ids.clear(); let owlry_version = env!("CARGO_PKG_VERSION");