Skip to content

Commit

Permalink
fix: use SafeChan preventing close channel multiple times (#30022)
Browse files Browse the repository at this point in the history
See also #29935

Signed-off-by: Congqi Xia <[email protected]>
  • Loading branch information
congqixia authored Jan 16, 2024
1 parent 7cb6beb commit c0f0548
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions internal/util/proxyutil/proxy_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (

"github.com/milvus-io/milvus/internal/util/sessionutil"
"github.com/milvus-io/milvus/pkg/log"
"github.com/milvus-io/milvus/pkg/util/lifetime"
"github.com/milvus-io/milvus/pkg/util/paramtable"
"github.com/milvus-io/milvus/pkg/util/typeutil"
)
Expand All @@ -53,7 +54,7 @@ type ProxyWatcher struct {
addSessionsFunc []func(*sessionutil.Session)
delSessionsFunc []func(*sessionutil.Session)

closeCh chan struct{}
closeCh lifetime.SafeChan
}

// NewProxyWatcher helper function to create a proxyWatcher
Expand All @@ -62,7 +63,7 @@ func NewProxyWatcher(client *clientv3.Client, fns ...func([]*sessionutil.Session
p := &ProxyWatcher{
lock: sync.Mutex{},
etcdCli: client,
closeCh: make(chan struct{}),
closeCh: lifetime.NewSafeChan(),
}
p.initSessionsFunc = append(p.initSessionsFunc, fns...)
return p
Expand Down Expand Up @@ -121,7 +122,7 @@ func (p *ProxyWatcher) startWatchEtcd(ctx context.Context, eventCh clientv3.Watc
log.Warn("stop watching etcd loop")
return

case <-p.closeCh:
case <-p.closeCh.CloseCh():
log.Warn("stop watching etcd loop")
return

Expand Down Expand Up @@ -218,6 +219,6 @@ func (p *ProxyWatcher) getSessionsOnEtcd(ctx context.Context) ([]*sessionutil.Se

// Stop stops the ProxyManager
func (p *ProxyWatcher) Stop() {
close(p.closeCh)
p.closeCh.Close()
p.wg.Wait()
}

0 comments on commit c0f0548

Please sign in to comment.