-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Remove temporary cached files #2625
Remove temporary cached files #2625
Conversation
/test e2e-openstack |
/test e2e-libvirt |
c0e8e31
to
807b95c
Compare
pkg/tfvars/internal/cache/cache.go
Outdated
@@ -96,6 +96,21 @@ func cacheFile(reader io.Reader, filePath string, sha256Checksum string) (err er | |||
} | |||
}() | |||
|
|||
// Make sure that the temp file does not exist after completion of the function | |||
defer func() { |
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.
so if we have the lock on the file above <file>.lock
and we have a tmp for that, should we just overwrite it or block it away?
or we could maybe create a tmp file, not anchored on the filename at all.
cc @wking because he did the initial implementation.
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 like the idea of giving temporary files random names!
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.
...should we just overwrite it or block it away?
I'm having trouble parsing this. Can you elaborate?
or we could maybe create a tmp file, not anchored on the filename at all.
Anchored on the filename is because we want to be in the same directory to setup for an atomic rename.
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.
...should we just overwrite it or block it away?
I'm having trouble parsing this. Can you elaborate?
since we know that we own the lock on the end file, we can either overwrite the file.tmp or remove the file.tmp if it exists and create a new one.
or we could maybe create a tmp file, not anchored on the filename at all.
Anchored on the filename is because we want to be in the same directory to setup for an atomic rename.
hhh, so rename is only atomic in same directory.. need to read a bit on it
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.
Oh, I think I understand "should we just overwrite it", and I think "yes, if we have the flock, we should be clobbering any pre-existing .tmp
file". That's somewhat orthogonal to this PR's current attempt to remove any dangling .tmp
file on exit. We could do both, although clobbering pre-existing .tmp
files is the only thing that will help in the "earlier installer was killed without having time to clean up" case.
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.
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.
@abhinavdahiya funny you said that, because one of the requirements for the checksum validation work is "Corrupted data should remain on disk for further investigation of the cause of failure", so I think you're right here.
pkg/tfvars/internal/cache/cache.go
Outdated
@@ -96,6 +96,21 @@ func cacheFile(reader io.Reader, filePath string, sha256Checksum string) (err er | |||
} | |||
}() | |||
|
|||
// Make sure that the temp file does not exist after completion of the function | |||
defer func() { | |||
_, err2 := os.Stat(tempPath) |
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.
Why bother with a racy Stat
? Just try os.Remove(tempPath)
and see if it works.
pkg/tfvars/internal/cache/cache.go
Outdated
// it manually. | ||
err3 := os.Remove(tempPath) | ||
if err3 != nil { | ||
err = err3 |
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 don't like clobbering err
unless it's nil
. I'm fine if you want to log an error you're about to discard though.
if err2 := os.Remove(tempPath); err2 != nil && !os.IsNotExist(err2) {
if err == nil {
err = err2
} else {
logrus.Errorf("failed to clean up %s: %v", tempPath, err2)
}
}
or some such.
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.
thanks! done as you said
807b95c
to
69a7231
Compare
Libvirt falls for a reason beyond the patch's control. Image download works well: level=debug msg="Generating Terraform Variables..." |
/test e2e-libvirt |
69a7231
to
50832f6
Compare
If the installer crashes (OOM, checksum validations, etc.) while downloading an OS image, temporary files remain in the system, clogging it. This commit makes sure that temporary files are deleted before starting a new download.
50832f6
to
fff7484
Compare
/close |
@Fedosin: Closed this PR. In response to this:
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. |
/reopen |
@Fedosin: Reopened this PR. In response to this:
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. |
@Fedosin: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. 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. I understand the commands that are listed here. |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Fedosin, mandre, wking 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 |
If the installer crashes (OOM, checksum validations, etc.) while downloading an OS image, temporary files remain in the system, clogging it.
This commit makes sure that temporary files are deleted before starting a new download.
Fixes: #1668