-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Try a temporary directory if the user cache fails #1800
Conversation
Welcome @skitt! |
Hi @skitt. Thanks for your PR. I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
8104aa8
to
27df424
Compare
/ok-to-test |
pkg/internal/testing/addr/manager.go
Outdated
if err != nil { | ||
baseDir = os.TempDir() | ||
// Either we didn't get a cache directory, or we can't use it | ||
cacheDir, err = tryCacheInDir(os.TempDir()) |
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.
I would actually vote for trying os.TempDir first, because a) it is more likely to succeed and more importantly b) it gets cleared upon reboot, which is not the case for UserCacheDir in most envs I think?
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.
Yup, UserCacheDir
doesn’t get cleaned up. I wanted to mostly preserve existing behaviour in this PR; were I to change that, I’d actually argue that UserCacheDir
isn’t really appropriate. It is defined as
There is a single base directory relative to which user-specific non-essential (cached) data should be written.
(Plus there’s the general idea in XDG that it’s for “real” users in a desktop environment...)
For lock-style files as used here, it seems to me that the appropriate directories are either /tmp
(as used historically, e.g. for X11 locks or SSH agent sockets) or /run
(but Go doesn’t wrap that).
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.
Hm yeah, I am really kinda surprised at seeing this here and wondering why that was done in the first place. Maybe os.Tempdir on MacOS is problematic? I don't have a Mac so I can't test that (quick google didn't show something, but that doesn't mean there is no issue). Do you remember @vincepri ?
Other than that this looks fine, except that the commit and pr title should be prefixed with :bug:
as documented in the PR template, could you please add that? We also have a check that should verify that, but it appears it is not working.
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.
Tempdir on Mac isn't really reliable so we switched to the CacheDir instead
Since commit 58c17f6 ("addr.Suggest should lock a file instead of memory"), pkg/internal/testing/addr/manager.go’s init() function tries to create a directory using either os.UserCacheDir() or os.TempDir(), whichever succeeds first. In many build environments, $HOME is non-empty but points to an unusable directory; in such cases, os.UserCacheDir() returns an unusable directory, which causes init() to panic. This changes init() to first try os.UserCacheDir(), including creating the desired directory; if that fails, the whole operation is tried again with os.TempDir(). Signed-off-by: Stephen Kitt <[email protected]>
27df424
to
a5708a1
Compare
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.
/approve
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: skitt, vincepri The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Thanks! |
Since commit 58c17f6 ("addr.Suggest should lock a file instead of
memory"), pkg/internal/testing/addr/manager.go’s init() function tries
to create a directory using either os.UserCacheDir() or os.TempDir(),
whichever succeeds first. In many build environments, $HOME is
non-empty but points to an unusable directory; in such cases,
os.UserCacheDir() returns an unusable directory, which causes init()
to panic.
This changes init() to first try os.UserCacheDir(), including creating
the desired directory; if that fails, the whole operation is tried
again with os.TempDir().
Fixes: #1799
Signed-off-by: Stephen Kitt [email protected]