tail: keep following moved descriptor when watch is lost #17002
adding RenameMode::Any here also changes the -F path below: on macOS a replaced file would now be reported as gone and its reader reset.
is it expected? if not, please limit it to the descriptor case
with this, the follow_descriptor_retry() branch below is no longer reached when a reader exists, so tail -f --retry f; rm f behaves differently now.
intended? please add a test for it
this ignores every error, not just a missing path. could you please only handle NotFound and keep the ? for the rest?
does this test fail on main? with inotify the watch on the inode should survive the move
thanks for picking this up!
This can't land yet: adding RenameMode::Any and reordering the Remove arm also change -F and -f --retry, and no test covers that (details inline). Please also check that the new test fails without the fix.
On Linux, watch_with_parent non-recursively watches the parent directory rather than the file inode.
As a result, when a file is moved to moved/f, only RenameMode::From is emitted and no subsequent append events are received at the destination—causing this to fail on main as well.
fixed it
fixed it
fixed it
5 functions (watch, watch_inner, watch_with_parent, try_watch_with_parent, watch_with_parent_inner) for one caller is a lot
could watch_with_parent just return the UResult<bool> and callers ignore it?
fixed it
<!-- __CODSPEED_PERFORMANCE_REPORT_COMMENT__ -->
Merging this PR will improve performance by 11.19%
<details>
<summary><b>1 warning, 1 note</b></summary>
:warning: 128 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
:information_source: 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
</details>
⚡ 3 improved benchmarks ✅ 420 untouched benchmarks ⏩ 78 skipped benchmarks[^skipped]
Performance Changes
| | Mode | Benchmark | BASE | HEAD | Efficiency |
| --- | ---- | --------- | ------ | ------ | ---------- |
| ⚡ | CPU Simulation | [` socket_addrs_direct[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Atail_follow_moved_descriptor?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Asocket_addrs_direct%255B100000%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 132.1 µs | 105.2 µs | +25.53% |
| ⚡ | CPU Simulation | [ hostname_ip_lookup[100000] ](https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Atail_follow_moved_descriptor?uri=src%2Fuu%2Fhostname%2Fbenches%2Fhostname_bench.rs%3A%3Ahostname_ip_lookup%255B100000%255D&runnerMode=Simulation&utm_source=github&utm_medium=comment-v2&utm_content=benchmark) | 573.3 µs | 545 µs | +5.2% |
| ⚡ | CPU Simulation | true_single_call | 1.4 µs | 1.4 µs | +4.08% |
[!TIP]
Curious why performance improved? Comment @codspeedbot explain why performance improved` on this PR, or directly use the CodSpeed MCP with your agent.
---
<sub>Comparing <code>mattsu2020:tail_follow_moved_descriptor</code> (d0a7b6c) with <code>main</code> (ba3f47d)[^unexpected-base]</sub>
<a href="https://app.codspeed.io/uutils/coreutils/branches/mattsu2020%3Atail_follow_moved_descriptor?utm_source=github&utm_medium=comment-v2&utm_content=button">
<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://codspeed.io/pr-report/open-in-codspeed-dark.svg">
<source media="(prefers-color-scheme: light)" srcset="https://codspeed.io/pr-report/open-in-codspeed-light.svg">
<img alt="Open in CodSpeed" src="https://codspeed.io/pr-report/open-in-codspeed-light.svg" width="169" height="32">
</picture>
</a>
[^skipped]: 78 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.
[^unexpected-base]: No successful run was found on <code>main</code> (ff93e0c) during the generation of this report, so ba3f47d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.
now every caller ignores NotFound, e.g. the initial watch_with_parent in start drops the false and the file is neither watched nor in orphans.
should it be pushed to orphans there too?
sylvestre
mattsu2020
Split out from #9093.
When following by descriptor (
tail -f), moving a file out of its watched directory or on backends that do not emitRenameMode::Bothdrops the watch on that file, so further appends stop being printed while events for other files arrive.Track moved open descriptors in
orphansso they are read on subsequent events and timeouts, guard the file-replacement reopen branch withfollow_name(), and add a regression test.