Fix reading config from etcd may block forever (#21688)

Signed-off-by: yah01 <yang.cen@zilliz.com>
This commit is contained in:
yah01 2023-01-13 11:29:41 +08:00 committed by GitHub
parent f8e1566b24
commit f4d80b4211
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,11 +21,16 @@ import (
"fmt"
"strings"
"sync"
"time"
"github.com/milvus-io/milvus/internal/util/etcd"
clientv3 "go.etcd.io/etcd/client/v3"
)
const (
ReadConfigTimeout = 3 * time.Second
)
type EtcdSource struct {
sync.RWMutex
etcdCli *clientv3.Client
@ -108,7 +113,9 @@ func (es *EtcdSource) SetEventHandler(eh EventHandler) {
func (es *EtcdSource) refreshConfigurations() error {
prefix := es.keyPrefix + "/config"
response, err := es.etcdCli.Get(es.ctx, prefix, clientv3.WithPrefix())
ctx, cancel := context.WithTimeout(es.ctx, ReadConfigTimeout)
defer cancel()
response, err := es.etcdCli.Get(ctx, prefix, clientv3.WithPrefix())
if err != nil {
return err
}