fix(daemon): use sub-second mtime precision in run index cache#390
Open
fix(daemon): use sub-second mtime precision in run index cache#390
Conversation
The run index cache used Unix() for mtime comparison, which only has second-level precision. When status events were appended within the same second, the cache would return stale data because the mtime change was not detected. This caused runs to show incorrect status (boot/fail) when they were actually running, because the daemon saw stale cached status instead of the updated status from disk. Changed to UnixNano() for nanosecond-precision mtime comparison, ensuring cache invalidation when files are modified. Fixes: orch-400
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
bootorfailwhen runs are actually running.Unix())Problem
The run index cache at
internal/store/file/run_index.gocompared file modification times using.Unix(), which truncates to second precision. When the daemon appended a status event (e.g.,running) and then immediately re-read the run list, the mtime comparison would pass (same second) and the stale cached status (e.g.,booting) would be returned.This caused:
bootstatus when they were actually runningfailstatus after dead checks when therunningstatus was already writtenFix
Changed mtime comparison from
.Unix()to.UnixNano()for nanosecond-precision comparison, ensuring the cache is properly invalidated when files are modified within the same second.Testing
go test ./internal/store/file/...,go test ./internal/daemon/...,go test ./internal/agent/...)go build ./...)Fixes