Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
allow holder to close/open/close without panic on closing closed channel
Browse files Browse the repository at this point in the history
  • Loading branch information
travisturner committed Oct 11, 2018
1 parent 396ec6e commit 69ef4a3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions holder.go
Expand Up @@ -101,6 +101,9 @@ func NewHolder() *Holder {

// Open initializes the root data directory for the holder.
func (h *Holder) Open() error {
// Reset closing in case Holder is being reopened.
h.closing = make(chan struct{})

h.setFileLimit()

h.Logger.Printf("open holder path: %s", h.Path)
Expand Down Expand Up @@ -178,6 +181,9 @@ func (h *Holder) Close() error {
}
}

// Reset opened in case Holder needs to be reopened.
h.opened = make(chan struct{})

return nil
}

Expand Down
10 changes: 10 additions & 0 deletions holder_internal_test.go
Expand Up @@ -287,3 +287,13 @@ func TestHolderCleaner_CleanHolder(t *testing.T) {
}
}
}

// Ensure holder can reopen.
func TestHolderCleaner_Reopen(t *testing.T) {
h := NewHolder()
h.Path = "path"
h.Open()
h.Close()
h.Open()
h.Close()
}

0 comments on commit 69ef4a3

Please sign in to comment.