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

close file handle after method is end in the global_state.go. #827

Closed
mei-rune opened this issue Aug 14, 2014 · 1 comment
Closed

close file handle after method is end in the global_state.go. #827

mei-rune opened this issue Aug 14, 2014 · 1 comment

Comments

@mei-rune
Copy link
Contributor

diff --git a/wal/global_state.go b/wal/global_state.go
index 92e3666..9b161ee 100644
--- a/wal/global_state.go
+++ b/wal/global_state.go
@@ -44,8 +44,10 @@ func newGlobalState(path string) (*GlobalState, error) {
        return nil, err
    }
    if err := state.read(f); err != nil {
+       f.Close()
        return nil, err
    }
+   f.Close()
    state.path = path
    return state, nil
 }
@@ -57,14 +59,17 @@ func (self *GlobalState) writeToFile() error {
    }

    if _, err := newFile.Seek(0, os.SEEK_SET); err != nil {
+       newFile.Close()
        return err
    }

    if err := self.write(newFile); err != nil {
+       newFile.Close()
        return err
    }

    if err := newFile.Sync(); err != nil {
+       newFile.Close()
        return err
    }

@@ -72,7 +77,9 @@ func (self *GlobalState) writeToFile() error {
        return err
    }

-   os.Remove(self.path)
+   if err := os.Remove(self.path); nil != err && !os.IsNotExist(err) {
+       return err
+   }
    return os.Rename(self.path+".new", self.path)
 }
@mei-rune
Copy link
Contributor Author

It isn't fix it.

@@ -32,6 +32,10 @@ type GlobalState struct {
func newGlobalState(path string) (*GlobalState, error) {
f, err := os.Open(path)
+ if err != nil {
+ defer f.Close()
+ }
+
state := &GlobalState{
ServerLastRequestNumber: map[uint32]uint32{},
ShardLastSequenceNumber: map[uint32]uint64{},

" if err != nil {" is error code, " if err == nil {" is ok.

pull request is "ensure close file before rename bookmark file. #840"

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

No branches or pull requests

1 participant