Skip to content

Commit

Permalink
karmada-search: Fix lock race affects watch RestChan not close, causi…
Browse files Browse the repository at this point in the history
…ng client watch api to hang

Signed-off-by: xigang <wangxiang2014@gmail.com>
  • Loading branch information
xigang committed Nov 11, 2023
1 parent 1b2c6ed commit f5fb699
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions pkg/search/proxy/store/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/klog/v2"

clusterv1alpha1 "github.com/karmada-io/karmada/pkg/apis/cluster/v1alpha1"
)
Expand Down Expand Up @@ -225,6 +226,11 @@ func (w *watchMux) Stop() {
}

func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch.Event)) {
defer func() {
if err := recover(); err != nil {
klog.Errorf("panic from watch source: %v", err)
}
}()
defer source.Stop()
defer w.Stop()
for {
Expand All @@ -246,19 +252,8 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch
select {
case <-w.done:
return
default:
case w.result <- copyEvent:
}

func() {
w.lock.RLock()
defer w.lock.RUnlock()
select {
case <-w.done:
return
default:
w.result <- copyEvent
}
}()
}
}

Expand Down

0 comments on commit f5fb699

Please sign in to comment.