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

fixed unclosed tmp file handle in filestore.go #6386

Closed
wants to merge 4 commits into from

Conversation

deem0n
Copy link
Contributor

@deem0n deem0n commented Jan 20, 2025

Static analyzer found unclosed filehandle tmpFD in case of errors. It is not strictly necessary as GC will eventually close tmpFD, but explicit call of Close is always better than magic finalizer.

Based on the discussion on SO

Signed-off-by: Dmitry Dorofeev dima@yasp.com

@deem0n deem0n requested a review from a team as a code owner January 20, 2025 16:27
Copy link
Member

@neilalexander neilalexander left a comment

Choose a reason for hiding this comment

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

LGTM

@neilalexander
Copy link
Member

FYI CI complaining about server/filestore.go:5841: File is not goimports-ed (goimports).

@deem0n
Copy link
Contributor Author

deem0n commented Jan 21, 2025

FYI CI complaining about server/filestore.go:5841: File is not goimports-ed (goimports).

checked locally with linter, it seems that I touched empty line:

diff --git a/server/filestore.go b/server/filestore.go
index 7b6df2ee..19ddd278 100644
--- a/server/filestore.go
+++ b/server/filestore.go
@@ -5762,7 +5762,7 @@ func (mb *msgBlock) recompressOnDiskIfNeeded() error {
        <-dios
        tmpFD, err := os.OpenFile(tmpFN, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, defaultFilePerms)
        dios <- struct{}{}
-
+
        if err != nil {
                return fmt.Errorf("failed to create temporary file: %w", err)
        }

Should I fix it with new commit to this PR?

@neilalexander
Copy link
Member

Please, although if you can squash down to a single commit, that'd be even better.

neilalexander and others added 3 commits January 21, 2025 14:21
Signed-off-by: Neil Twigg <neil@nats.io>
Signed-off-by: Neil Twigg <neil@nats.io>
Static analyzer found unclosed filehandle tmpFD in case of errors. It is not strictly necessary as GC will eventually close tmpFD, but explicit call of Close is always better than magic finalizer.

Signed-off-by: Dmitry Dorofeev <dima@yasp.com>
@neilalexander
Copy link
Member

I think the reason you have main commits showing (and GH showing the branch out of date) is because you need to rebase against the latest main branch.

@deem0n
Copy link
Contributor Author

deem0n commented Jan 21, 2025

I think the reason you have main commits showing (and GH showing the branch out of date) is because you need to rebase against the latest main branch.

I guess it will be easier to make completely new PR with just one commit, my git-fu is not that good :-)
I will just wait for travis to complete to see if it happy now with empty line

@deem0n deem0n closed this by deleting the head repository Jan 21, 2025
@deem0n
Copy link
Contributor Author

deem0n commented Jan 21, 2025

Reopened as #6390

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants