From 61e83a1c869d81483c24c724eca061391b982d05 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 7 Dec 2025 21:00:03 +0100 Subject: [PATCH] tail: fix intermittent overlay-headers test by batching inotify events --- src/uu/tail/src/follow/watch.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/uu/tail/src/follow/watch.rs b/src/uu/tail/src/follow/watch.rs index 11e367918..7368617e1 100644 --- a/src/uu/tail/src/follow/watch.rs +++ b/src/uu/tail/src/follow/watch.rs @@ -576,9 +576,17 @@ pub fn follow(mut observer: Observer, settings: &Settings) -> UResult<()> { // Drain any additional pending events to batch them together. // This prevents redundant headers when multiple inotify events // are queued (e.g., after resuming from SIGSTOP). - while let Ok(Ok(event)) = observer.watcher_rx.as_mut().unwrap().receiver.try_recv() - { - process_event(&mut observer, event, settings, &mut paths)?; + // Multiple iterations with spin_loop hints give the notify + // background thread chances to deliver pending events. + for _ in 0..100 { + while let Ok(Ok(event)) = + observer.watcher_rx.as_mut().unwrap().receiver.try_recv() + { + process_event(&mut observer, event, settings, &mut paths)?; + } + // Use both yield and spin hint for broader CPU support + std::thread::yield_now(); + std::hint::spin_loop(); } } Ok(Err(notify::Error {