Skip to content

tail:Fix tail -f sparse file growth handling#12080

Open
mattsu2020 wants to merge 3 commits into
uutils:mainfrom
mattsu2020:tail_12015
Open

tail:Fix tail -f sparse file growth handling#12080
mattsu2020 wants to merge 3 commits into
uutils:mainfrom
mattsu2020:tail_12015

Conversation

@mattsu2020
Copy link
Copy Markdown
Contributor

Summary

Fixes tail -f behavior when a followed sparse file grows by a very large amount, such as via truncate -s 1P.

The follow path previously used BytesChunkBuffer::new(u64::MAX), which consumed all newly readable bytes into memory before printing. For sparse file holes, those bytes are read as NULs, so a large logical size increase could cause tail to consume excessive memory and get killed.

This changes follow-mode output to read one chunk to detect whether new data exists and preserve header behavior, then stream the remaining data directly to stdout with io::copy.

Fixes #12015.

Validation

  • cargo fmt --check
  • cargo check -p uu_tail
  • cargo test -p uu_tail
  • cargo build -p coreutils
  • cargo test --test tests test_n0_with_follow --features tail
  • Manual sparse growth check with tail -n0 -f --use-polling and truncate -s 1P

@mattsu2020 mattsu2020 changed the title [codex] Fix tail -f sparse file growth handling tail:Fix tail -f sparse file growth handling Apr 29, 2026
@mattsu2020 mattsu2020 marked this pull request as ready for review April 29, 2026 12:12
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 29, 2026

GNU testsuite comparison:

Skip an intermittent issue tests/date/date-locale-hour (fails in this run but passes in the 'main' branch)
Congrats! The gnu test tests/rm/many-dir-entries-vs-OOM is now passing!

Comment thread src/uu/tail/src/follow/files.rs Outdated
return Ok(false);
};

let result = (|| -> UResult<bool> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make this a named function?

Copy link
Copy Markdown
Contributor

@Alonely0 Alonely0 May 1, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not even sure there was a need for that in the first place... this is a weird JS idiom that popped up after I noped out of there. The new added function looks fine tho.

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 29, 2026

Merging this PR will degrade performance by 3.11%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 regressed benchmark
✅ 310 untouched benchmarks
⏩ 46 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation du_max_depth_balanced_tree[(6, 4, 10)] 25 ms 25.8 ms -3.11%

Comparing mattsu2020:tail_12015 (628aee0) with main (45a48a1)

Open in CodSpeed

Footnotes

  1. 46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Comment thread src/uu/tail/src/follow/files.rs Outdated
mattsu2020 and others added 3 commits May 4, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tail -f file SIGABRT if file size increased 1PB

3 participants