Skip to content

Commit 8a7e1a8

Browse files
committed
Prevent panic on duplicate Delete (storage)
1 parent 58c0878 commit 8a7e1a8

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/storage/local_storage.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"context"
2727
"fmt"
2828
"reflect"
29+
"sync/atomic"
2930
"time"
3031

3132
"github.com/rs/zerolog"
@@ -89,6 +90,7 @@ type LocalStorage struct {
8990

9091
eventCh chan *localStorageEvent
9192
stopCh chan struct{}
93+
stopped int32
9294

9395
eventsCli corev1.EventInterface
9496

@@ -136,7 +138,9 @@ func (ls *LocalStorage) Update(apiObject *api.ArangoLocalStorage) {
136138
// Called when the local storage was deleted by the user.
137139
func (ls *LocalStorage) Delete() {
138140
ls.deps.Log.Info().Msg("local storage is deleted by user")
139-
close(ls.stopCh)
141+
if atomic.CompareAndSwapInt32(&ls.stopped, 0, 1) {
142+
close(ls.stopCh)
143+
}
140144
}
141145

142146
// send given event into the local storage event queue.

0 commit comments

Comments
 (0)