Skip to content

tail: do not panic when the file is truncated while scanning backwards - #16042

Open
Logic769 wants to merge 5 commits into
uutils:mainfrom
Logic769:tail-truncated-file-no-panic
Open

Logic769 wants to merge 5 commits into
uutils:mainfrom
Logic769:tail-truncated-file-no-panic

Conversation

@Logic769

Copy link
Copy Markdown
Contributor

ReverseChunks measures the file size once in new() and then calls
read_exact(...).unwrap() for every block. If the file is truncated (for
example by log rotation or another writer) after the size was measured, the
backwards seek still succeeds but the read returns UnexpectedEof, so
tail -n N FILE panics with exit status 101 (or SIGABRT in release builds).

Treat a failed read in the backwards scan as the start of the file instead of
panicking, so a concurrently truncated file no longer aborts tail. GNU tail
also exits successfully in this situation.

A unit test covers the truncation-after-measurement case.

Closes #15755

@sylvestre

Copy link
Copy Markdown
Contributor

@Logic769 this is my last warning.
Please stop ignoring my messages...

@sylvestre

Copy link
Copy Markdown
Contributor

@Logic769 as I asked you many time to stop pushing a lot of patches and you ignored me, i have no other solutions than to block you temporarily.

@Logic769
Logic769 force-pushed the tail-truncated-file-no-panic branch from 38caad2 to 6184afe Compare October 30, 2026 13:02
Comment thread src/uu/tail/src/chunks.rs Resolved
Comment thread src/uu/tail/src/chunks.rs Resolved
Comment thread src/uu/tail/src/chunks.rs Resolved
@codspeed

codspeed Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

1 warning, 1 note

⚠️ 123 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

ℹ️ 1 benchmark has no flamegraph

The flamegraph wasn't generated: most of the time was spent in runtime internals, which would leave nothing useful to analyze.

See affected benchmarks

✅ 401 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing Logic769:tail-truncated-file-no-panic (0eca556) with main (8e267ce)2

Open in CodSpeed

Footnotes

  1. 70 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. ↩

  2. No successful run was found on main (19f6602) during the generation of this report, so 8e267ce was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for looking into this!
real read errors still end in a panic, so tail still aborts. please return them as errors instead, see the inline comments.

Comment thread src/uu/tail/src/chunks.rs Resolved
Comment thread src/uu/tail/src/chunks.rs Resolved
@sylvestre
sylvestre force-pushed the tail-truncated-file-no-panic branch from c4fcf65 to 56ed444 Compare November 2, 2026 23:40
@sylvestre

Copy link
Copy Markdown
Contributor

a bunch of jobs are failing

This branch has not been deployed

No deployments
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: panic in ReverseChunks when the file is truncated mid-scan

2 participants