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 4eadcdf
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions pkg/search/proxy/store/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,16 @@ type decoratedWatcher struct {
}

type watchMux struct {
lock sync.RWMutex
sources []decoratedWatcher
result chan watch.Event
done chan struct{}
lock sync.RWMutex
sources []decoratedWatcher
result chan watch.Event
done chan struct{}
}

func newWatchMux() *watchMux {
return &watchMux{
result: make(chan watch.Event),
done: make(chan struct{}),
result: make(chan watch.Event, 100),
done: make(chan struct{}),
}
}

Expand Down Expand Up @@ -227,6 +227,7 @@ func (w *watchMux) Stop() {
func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch.Event)) {
defer source.Stop()
defer w.Stop()

for {
var copyEvent watch.Event
select {
Expand All @@ -250,13 +251,10 @@ func (w *watchMux) startWatchSource(source watch.Interface, decorator func(watch
}

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

0 comments on commit 4eadcdf

Please sign in to comment.