Skip to content
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

[Federation]Fix forgeting to close file #48013

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ func newControllerWithTestServer(f func(w http.ResponseWriter, r *http.Request),
if err != nil {
return nil, err
}
defer file.Close()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The defer call a few lines above (https://github.com/kubernetes/kubernetes/pull/48013/files#diff-a277f7e642ed73686876c214453fab77R340) removes the file entirely. Is it really required to close it in a defer call that just executes before remove?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid accidents, I think closing file after opening it more safe.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@FengyunPan out of curiosity, what kind of accidents? In theory, I agree with what you are saying. But in this particular case, does it apply or matter?


controller, err := newAdmissionController(file)
if err != nil {
Expand Down