Skip to content

Commit 4087e30

Browse files
committed
Bugfix: File watcher panicked on 500+ external changes
- `handle_directory_change_incremental` falls back to a full reread when a debouncer batch has more than 500 events, and the error path in the debouncer callback did the same. Both used `tokio::spawn`, but the callback runs on the `notify-rs` debouncer thread which has no Tokio runtime context, so the spawn panicked (`there is no reactor running`) and the full-reread event never reached the frontend. - Switch to `tauri::async_runtime::spawn` (same pattern `indexing::watcher` already uses for the same reason). - Fixes `file-watching.spec.ts` "handles 600+ files" on Linux Docker.
1 parent dd06d68 commit 4087e30

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

apps/desktop/src-tauri/src/file_system/watcher.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ pub fn start_watching(listing_id: &str, path: &Path) -> Result<(), String> {
130130
// Watcher errors often mean the watched directory was deleted.
131131
// Try to re-read; if it fails with NotFound, we'll emit directory-deleted.
132132
let lid = listing_for_closure.clone();
133-
tokio::spawn(async move { handle_directory_change(&lid).await });
133+
tauri::async_runtime::spawn(async move { handle_directory_change(&lid).await });
134134
}
135135
}
136136
},
@@ -169,7 +169,10 @@ fn handle_directory_change_incremental(listing_id: &str, events: Vec<DebouncedEv
169169
.any(|e| matches!(e.kind, EventKind::Any | EventKind::Other))
170170
{
171171
let lid = listing_id.to_string();
172-
tokio::spawn(async move { handle_directory_change(&lid).await });
172+
// `tauri::async_runtime::spawn` instead of `tokio::spawn` because this
173+
// closure runs on the notify-rs debouncer thread, which has no Tokio
174+
// runtime context. Tauri's async runtime works from any thread.
175+
tauri::async_runtime::spawn(async move { handle_directory_change(&lid).await });
173176
return;
174177
}
175178

0 commit comments

Comments
 (0)