-
Notifications
You must be signed in to change notification settings - Fork 122
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
ensure filehandles are closed #173
Conversation
I can't reproduce this locally... I think it is a legit error:
|
I'd be okay with disabling at least this lint message due to this reasoning.
|
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.
Thank you for tracking down the problem and opening this PR! You are absolutely correct this missing fh.Close()
is a problem. golangci-lint
has linters for catching missing close on http response bodies, and sql rows, but apparently not for file handlers unfortunately.
That article is a great reminder about how to safely handle writes. Thankfully in this case we are only doing reads (https://golang.org/pkg/os/#Open, "Open opens the named file for reading"). I believe that explains the panic we see from windows. I guess on linux it is not an error to try and sync with a read-only handle, but on windows it is.
Since this is read-only we can remove the fh.Sync()
, there isn't anything to sync.
I agree we can also ignore the lint error about the ignored return, we don't care about errors in this case because it is read-only.
I've added some suggested edits which should resolve the build errors. I'll apply those and merge once CI is happy.
LGTM! CI is happy with those changes! |
See https://www.joeshaw.org/dont-defer-close-on-writable-files/