-
Notifications
You must be signed in to change notification settings - Fork 283
fix: data races in tests and NFS cache scanner #2256
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 The
statInDirerror message instat_linux.gostill formats only the barefilenameinstead of the full pathfilepath.Join(dirPath, filename)that is already computed on line 37 for the syscall. On NFS errors likeESTALEorENOENT, operators see only"failed to statx \"abc123.squashfs\": stale file handle"with no directory context, making root-cause analysis harder. Fix: replacefilenamewithfilepath.Join(dirPath, filename)in thefmt.Errorfcall.Extended reasoning...
What the bug is
After this PR's refactor,
statInDirinstat_linux.gotakesdirPath stringinstead ofdf *os.File. Line 37 explicitly computes the full path asfilepath.Join(dirPath, filename)to pass tounix.Statx. However, the error message on line 43 was not updated and still uses only the shortfilename:The specific inconsistency
The sibling
stat()function correctly usesfullPathin its error message:The full path
filepath.Join(dirPath, filename)is computed two lines above the error check but not reused in the diagnostic.Why existing code doesn't prevent it
Before this PR,
statInDirtookdf *os.Fileand calledunix.Statx(int(df.Fd()), filename, ...)— the full path was not a named local variable (though available viafilepath.Join(df.Name(), filename)). The old error message logging onlyfilenamewas a pre-existing omission. This PR changes the signature specifically to pass the directory path as a string, and computesfilepath.Join(dirPath, filename)explicitly, but leaves the error format unchanged.Impact
When NFS-related errors occur (
ESTALE,ENOENT,EIO), the log line reads:failed to statx "abc123.squashfs": stale file handle. Without the directory context, an operator cannot determine which NFS mount or subdirectory is affected — particularly problematic in large NFS caches with many subdirectories containing files of the same name.How to fix
On line 43 of
stat_linux.go, replacefilenamewithfilepath.Join(dirPath, filename):Step-by-step proof
scanDircomputesabsPath(e.g.,/nfs/cache/subdir) and sendsstatReq{dirPath: absPath, name: "abc123.squashfs"}.StattercallsstatInDir("/nfs/cache/subdir", "abc123.squashfs").filepath.Join("/nfs/cache/subdir", "abc123.squashfs")="/nfs/cache/subdir/abc123.squashfs"and passes it tounix.Statx.err=ESTALE."failed to statx \"abc123.squashfs\": stale file handle"— directory context/nfs/cache/subdiris absent."failed to statx \"/nfs/cache/subdir/abc123.squashfs\": stale file handle"— fully actionable.Addressing the pre-existing objection
One verifier correctly notes this is pre-existing behavior — the error message used only
filenamebefore and after this PR, so no regression is introduced. This is classified as nit rather than normal severity. However, this PR is the ideal time to fix it: it changes the function signature specifically to makedirPathavailable, computes the full path on line 37, and the one-character fix makes the diagnostic consistent with the siblingstat()function.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed — statInDir now stores the full path in a variable and uses it in both the Statx call and the error message.