From 61e83a1c869d81483c24c724eca061391b982d05 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 7 Dec 2025 21:00:03 +0100 Subject: [PATCH 1/2] 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 { From adafa2fdd91f7cdcdf9f238ea8ee47c9624c5de6 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 7 Dec 2025 23:56:37 +0100 Subject: [PATCH 2/2] tail: add debug info --- util/gnu-patches/series | 1 + .../tests_tail_overlay_headers.patch | 49 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 util/gnu-patches/tests_tail_overlay_headers.patch diff --git a/util/gnu-patches/series b/util/gnu-patches/series index 5fb1398cd..451fe99da 100644 --- a/util/gnu-patches/series +++ b/util/gnu-patches/series @@ -11,3 +11,4 @@ tests_tsort.patch tests_du_move_dir_while_traversing.patch test_mkdir_restorecon.patch error_msg_uniq.diff +tests_tail_overlay_headers.patch diff --git a/util/gnu-patches/tests_tail_overlay_headers.patch b/util/gnu-patches/tests_tail_overlay_headers.patch new file mode 100644 index 000000000..205401294 --- /dev/null +++ b/util/gnu-patches/tests_tail_overlay_headers.patch @@ -0,0 +1,49 @@ +--- gnu.orig/tests/tail/overlay-headers.sh 2025-12-07 23:20:20.566198669 +0100 ++++ gnu/tests/tail/overlay-headers.sh 2025-12-07 23:20:20.570198688 +0100 +@@ -56,26 +56,39 @@ + + kill -0 $pid || fail=1 + +-# Wait for 5 initial lines +-retry_delay_ wait4lines_ .1 6 5 || fail=1 ++# Wait for 5 initial lines (2 headers + 2 content lines + 1 blank) ++retry_delay_ wait4lines_ .1 6 5 || { echo "Failed waiting for initial 5 lines"; fail=1; } ++ ++echo "=== After initial wait, line count: $(countlines_) ===" ++echo "=== Initial output: ===" && cat out && echo "=== End initial output ===" + + # Suspend tail so single read() caters for multiple inotify events +-kill -STOP $pid || fail=1 ++kill -STOP $pid || { echo "Failed to STOP tail process"; fail=1; } + + # Interleave writes to files to generate overlapping inotify events + echo line >> file1 || framework_failure_ + echo line >> file2 || framework_failure_ + echo line >> file1 || framework_failure_ + echo line >> file2 || framework_failure_ ++echo "=== Files written, resuming tail ===" + + # Resume tail processing +-kill -CONT $pid || fail=1 ++kill -CONT $pid || { echo "Failed to CONT tail process"; fail=1; } + +-# Wait for 8 more lines +-retry_delay_ wait4lines_ .1 6 13 || fail=1 ++# Wait for 8 more lines (should total 13) ++retry_delay_ wait4lines_ .1 6 13 || { echo "Failed waiting for 13 total lines"; fail=1; } + + kill $sleep && wait || framework_failure_ + +-test "$(countlines_)" = 13 || fail=1 ++final_count=$(countlines_) ++echo "=== Final line count: $final_count (expected 13) ===" ++ ++if test "$final_count" != 13; then ++ echo "=== FAILURE: Expected 13 lines, got $final_count ===" ++ echo "=== Full output content: ===" ++ cat -A out ++ echo "=== End output content ===" ++ fail=1 ++fi + + Exit $fail