From 8a7e1a8603522661a66996af0dda04b9c953412f Mon Sep 17 00:00:00 2001 From: Ewout Prangsma Date: Thu, 5 Apr 2018 08:47:59 +0200 Subject: [PATCH] Prevent panic on duplicate Delete (storage) --- pkg/storage/local_storage.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkg/storage/local_storage.go b/pkg/storage/local_storage.go index 9e1c2b437..2591bda6d 100644 --- a/pkg/storage/local_storage.go +++ b/pkg/storage/local_storage.go @@ -26,6 +26,7 @@ import ( "context" "fmt" "reflect" + "sync/atomic" "time" "github.com/rs/zerolog" @@ -89,6 +90,7 @@ type LocalStorage struct { eventCh chan *localStorageEvent stopCh chan struct{} + stopped int32 eventsCli corev1.EventInterface @@ -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.