From d40d70c600b4ab14741cd609f7f64001c3bbc249 Mon Sep 17 00:00:00 2001 From: dailz Date: Thu, 4 Jun 2026 14:33:40 +0800 Subject: [PATCH] fix(watcher): use try_send to prevent blocking notify callback Replace tx.send() with tx.try_send() in file watcher notify callback to avoid blocking the notify thread when the bounded channel (cap 100) is full. Events are silently dropped instead of blocking, preventing shutdown delays and event loss during consumer stalls. Closes #7 --- crates/core/src/watcher/file_watcher.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/core/src/watcher/file_watcher.rs b/crates/core/src/watcher/file_watcher.rs index 4420068..795be03 100644 --- a/crates/core/src/watcher/file_watcher.rs +++ b/crates/core/src/watcher/file_watcher.rs @@ -62,7 +62,7 @@ impl FileWatcher { match event.kind { EventKind::Modify(_) | EventKind::Create(_) | EventKind::Any => {} EventKind::Remove(_) => { - let _ = tx.send(FileEvent::Removed); + let _ = tx.try_send(FileEvent::Removed); return; } _ => return, @@ -83,19 +83,19 @@ impl FileWatcher { }); if current_inode != 0 && st.last_inode != 0 && current_inode != st.last_inode { - let _ = tx.send(FileEvent::Rotated { + let _ = tx.try_send(FileEvent::Rotated { new_inode: current_inode, }); st.last_inode = current_inode; st.last_size = current_size; } else if current_size > st.last_size { - let _ = tx.send(FileEvent::Appended { + let _ = tx.try_send(FileEvent::Appended { new_size: current_size, }); st.last_size = current_size; st.last_inode = current_inode; } else if current_size < st.last_size { - let _ = tx.send(FileEvent::Truncated { + let _ = tx.try_send(FileEvent::Truncated { new_size: current_size, }); st.last_size = current_size;