Skip to content

Commit

Permalink
Prevent panic on duplicate Delete (storage)
Browse files Browse the repository at this point in the history
  • Loading branch information
ewoutp committed Apr 5, 2018
1 parent 58c0878 commit 8a7e1a8
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/storage/local_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"context"
"fmt"
"reflect"
"sync/atomic"
"time"

"github.com/rs/zerolog"
Expand Down Expand Up @@ -89,6 +90,7 @@ type LocalStorage struct {

eventCh chan *localStorageEvent
stopCh chan struct{}
stopped int32

eventsCli corev1.EventInterface

Expand Down Expand Up @@ -136,7 +138,9 @@ func (ls *LocalStorage) Update(apiObject *api.ArangoLocalStorage) {
// Called when the local storage was deleted by the user.
func (ls *LocalStorage) Delete() {
ls.deps.Log.Info().Msg("local storage is deleted by user")
close(ls.stopCh)
if atomic.CompareAndSwapInt32(&ls.stopped, 0, 1) {
close(ls.stopCh)
}
}

// send given event into the local storage event queue.
Expand Down

0 comments on commit 8a7e1a8

Please sign in to comment.