Skip to content

Read the current second for stat signatures off the filesystem clock - #7189

Merged
ondrejmirtes merged 1 commit into
2.3.xfrom
fix/filesystem-clock-stat-signatures
Nov 26, 2026
Merged

ondrejmirtes merged 1 commit into
2.3.xfrom
fix/filesystem-clock-stat-signatures

Conversation

@ondrejmirtes

Copy link
Copy Markdown
Member

The kernel stamps files with a clock that advances only on a timer tick (ktime_get_coarse_real_ts64), so for a few milliseconds after time() moves to the next second, a file or directory written still gets the previous second. FileStatSignatures::begin() compared timestamps to time(), so FileStatSignatureReader vouched for such a change: a DirectoryWalker listing, or a file hash in the result cache, could be reused over different contents.

This is what made DirectoryWalkerTest (testListingsSeeAddedAndRemovedFiles, testReplacedDirectoryIsReadAgain) fail now and then in the full test suite: the test's changes sometimes landed in that window right after waitUntilTheTreeIsInThePast() returned.

begin() now reads the current second off the mtime of a tmpfile() it creates, the way git compares to the mtime of its index. If the probe cannot be created, it falls back to time() - 1, which treats the last second as racy too.

Evidence on an ext4 orb:

  • Changing a directory right after begin() and asking for its signature: before, 1784 of 347782 changes still got a signature; after, 0 of 172356.
  • DirectoryWalkerTest with all 16 cores busy: failed 2 of 6 runs before, passed 8 of 8 after.

ResultCacheManager::hashAnalysedFiles() has the same lag in its $hashedAt = time() racy check; it is left for a follow-up.

Amp thread: https://ampcode.com/threads/T-01a21723-3824-7286-98c0-56d7b4e30d96

The kernel stamps files with a clock that advances only on a timer tick,
so for a few milliseconds after time() moves to the next second, a file
or directory written still gets the previous second. FileStatSignatures
compared timestamps to time(), so it vouched for such a change and a
DirectoryWalker listing or a result cache file hash could be reused over
different contents. This made DirectoryWalkerTest fail now and then when
the whole test suite was run.

The current second is now read off the mtime of a temporary file created
in begin(), the way git compares to the mtime of its index.

Amp-Thread-ID: https://ampcode.com/threads/T-01a21723-3824-7286-98c0-56d7b4e30d96
@ondrejmirtes
ondrejmirtes merged commit 712fb79 into 2.3.x Nov 26, 2026
311 of 313 checks passed
@ondrejmirtes
ondrejmirtes deleted the fix/filesystem-clock-stat-signatures branch November 26, 2026 11:45
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.

1 participant