diff --git a/doc/wiki-cn/warden-resolver.md b/doc/wiki-cn/warden-resolver.md index 96585f193..0e84a9044 100644 --- a/doc/wiki-cn/warden-resolver.md +++ b/doc/wiki-cn/warden-resolver.md @@ -219,6 +219,7 @@ const AppID = "demo.service" // NOTE: example func init(){ // NOTE: 注意这段代码,表示要使用etcd进行服务发现 ,其他事项参考discovery的说明 // NOTE: 在启动应用时,可以通过flag(-etcd.endpoints) 或者 环境配置(ETCD_ENDPOINTS)指定etcd节点 + // NOTE: 如果需要自己指定配置时 需要同时设置DialTimeout 与 DialOptions: []grpc.DialOption{grpc.WithBlock()} resolver.Register(etcd.Builder(nil)) } diff --git a/pkg/naming/etcd/etcd.go b/pkg/naming/etcd/etcd.go index 846baa7bc..0a9b9d9ee 100644 --- a/pkg/naming/etcd/etcd.go +++ b/pkg/naming/etcd/etcd.go @@ -16,6 +16,7 @@ import ( "github.com/bilibili/kratos/pkg/naming" "go.etcd.io/etcd/clientv3" "go.etcd.io/etcd/mvcc/mvccpb" + "google.golang.org/grpc" ) var ( @@ -99,6 +100,7 @@ func New(c *clientv3.Config) (e *EtcdBuilder, err error) { c = &clientv3.Config{ Endpoints: strings.Split(endpoints, ","), DialTimeout: time.Second * time.Duration(defaultDialTimeout), + DialOptions: []grpc.DialOption{grpc.WithBlock()}, } } cli, err := clientv3.New(*c) diff --git a/pkg/naming/etcd/etcd_test.go b/pkg/naming/etcd/etcd_test.go index e774346ec..72d15aa15 100644 --- a/pkg/naming/etcd/etcd_test.go +++ b/pkg/naming/etcd/etcd_test.go @@ -3,10 +3,11 @@ package etcd import ( "context" "fmt" - "github.com/bilibili/kratos/pkg/naming" - "go.etcd.io/etcd/clientv3" "testing" "time" + "github.com/bilibili/kratos/pkg/naming" + "go.etcd.io/etcd/clientv3" + "google.golang.org/grpc" ) func TestNew(t *testing.T) { @@ -14,6 +15,7 @@ func TestNew(t *testing.T) { config := &clientv3.Config{ Endpoints: []string{"127.0.0.1:2379"}, DialTimeout: time.Second * 3, + DialOptions: []grpc.DialOption{grpc.WithBlock()}, } builder, err := New(config)