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 temp files, fix path print #2152

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion server/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ func newFileStoreWithCreated(fcfg FileStoreConfig, cfg StreamConfig, created tim
if err != nil {
return nil, fmt.Errorf("storage directory is not writable")
}
tmpfile.Close()
os.Remove(tmpfile.Name())

fs := &fileStore{
Expand Down Expand Up @@ -3192,7 +3193,12 @@ func (mb *msgBlock) close(sync bool) {
if sync {
syncAndClose(mb.mfd, mb.ifd)
} else {
go syncAndClose(mb.mfd, mb.ifd)
if mb.mfd != nil {
mb.mfd.Close()
}
if mb.ifd != nil {
mb.ifd.Close()
}
}
mb.mfd = nil
mb.ifd = nil
Expand All @@ -3209,6 +3215,14 @@ func (fs *fileStore) Delete() error {
return ErrStoreClosed
}
fs.Purge()

pdir := path.Join(fs.fcfg.StoreDir, purgeDir)
// If purge directory still exists then we need to wait
// in place and remove since rename would fail.
if _, err := os.Stat(pdir); err == nil {
os.RemoveAll(pdir)
}

if err := fs.Stop(); err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion server/jetstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ func (s *Server) enableJetStream(cfg JetStreamConfig) error {
if err != nil {
return fmt.Errorf("storage directory is not writable")
}
tmpfile.Close()
os.Remove(tmpfile.Name())
}

Expand All @@ -199,7 +200,7 @@ func (s *Server) enableJetStream(cfg JetStreamConfig) error {
s.Noticef("---------------- JETSTREAM ----------------")
s.Noticef(" Max Memory: %s", friendlyBytes(cfg.MaxMemory))
s.Noticef(" Max Storage: %s", friendlyBytes(cfg.MaxStore))
s.Noticef(" Store Directory: %q", cfg.StoreDir)
s.Noticef(" Store Directory: \"%s\"", cfg.StoreDir)
s.Noticef("-------------------------------------------")

// Setup our internal subscriptions.
Expand Down
1 change: 1 addition & 0 deletions server/raft.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ func (s *Server) bootstrapRaftNode(cfg *RaftConfig, knownPeers []string, allPeer
if err != nil {
return fmt.Errorf("raft: storage directory is not writable")
}
tmpfile.Close()
os.Remove(tmpfile.Name())

return writePeerState(cfg.Store, &peerState{knownPeers, expected})
Expand Down