File tree Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Expand file tree Collapse file tree 4 files changed +16
-4
lines changed Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ require (
25
25
golang.org/x/time v0.3.0
26
26
google.golang.org/protobuf v1.34.2
27
27
gopkg.in/evanphx/json-patch.v4 v4.12.0
28
- k8s.io/api v0.0.0-20240722223049-b689d905290f
28
+ k8s.io/api v0.0.0-20240723194852-3421a80713ae
29
29
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe
30
30
k8s.io/klog/v2 v2.130.1
31
31
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340
Original file line number Diff line number Diff line change @@ -156,8 +156,8 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
156
156
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
157
157
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA =
158
158
gopkg.in/yaml.v3 v3.0.1 /go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM =
159
- k8s.io/api v0.0.0-20240722223049-b689d905290f h1:wtqzslJEcheiQ7hXjw1yGfqUyMCb7G4j72aL64Bzpbo =
160
- k8s.io/api v0.0.0-20240722223049-b689d905290f /go.mod h1:ytlEzqC2wOTwYET71W7+J+k7O2V7vrDuzmNLBSpgT+k =
159
+ k8s.io/api v0.0.0-20240723194852-3421a80713ae h1:mV43yijQh5/Wf7fwSuyATasDFY+YJxjuXs1ecY5M1Bc =
160
+ k8s.io/api v0.0.0-20240723194852-3421a80713ae /go.mod h1:ytlEzqC2wOTwYET71W7+J+k7O2V7vrDuzmNLBSpgT+k =
161
161
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe h1:V9MwpYUwbKlfLKVrhpVuKWiat/LBIhm1pGB9/xdHm5Q =
162
162
k8s.io/apimachinery v0.0.0-20240720202316-95b78024e3fe /go.mod h1:rsPdaZJfTfLsNJSQzNHQvYoTmxhoOEofxtOsF3rtsMo =
163
163
k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk =
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import (
22
22
"fmt"
23
23
"io"
24
24
"net/http"
25
+ "sync"
25
26
"time"
26
27
27
28
apierrors "k8s.io/apimachinery/pkg/api/errors"
@@ -53,6 +54,7 @@ type RetryWatcher struct {
53
54
stopChan chan struct {}
54
55
doneChan chan struct {}
55
56
minRestartDelay time.Duration
57
+ stopChanLock sync.Mutex
56
58
}
57
59
58
60
// NewRetryWatcher creates a new RetryWatcher.
@@ -286,7 +288,15 @@ func (rw *RetryWatcher) ResultChan() <-chan watch.Event {
286
288
287
289
// Stop implements Interface.
288
290
func (rw * RetryWatcher ) Stop () {
289
- close (rw .stopChan )
291
+ rw .stopChanLock .Lock ()
292
+ defer rw .stopChanLock .Unlock ()
293
+
294
+ // Prevent closing an already closed channel to prevent a panic
295
+ select {
296
+ case <- rw .stopChan :
297
+ default :
298
+ close (rw .stopChan )
299
+ }
290
300
}
291
301
292
302
// Done allows the caller to be notified when Retry watcher stops.
Original file line number Diff line number Diff line change @@ -585,6 +585,8 @@ func TestRetryWatcherToFinishWithUnreadEvents(t *testing.T) {
585
585
// Give the watcher a chance to get to sending events (blocking)
586
586
time .Sleep (10 * time .Millisecond )
587
587
588
+ watcher .Stop ()
589
+ // Verify a second stop does not cause a panic
588
590
watcher .Stop ()
589
591
590
592
maxTime := time .Second
You can’t perform that action at this time.
0 commit comments