fix: grpc connectTimeout
diff --git a/protocol/grpc/client.go b/protocol/grpc/client.go
index 24ab125..bbf4285 100644
--- a/protocol/grpc/client.go
+++ b/protocol/grpc/client.go
@@ -20,6 +20,7 @@
import (
"reflect"
"strconv"
+ "time"
)
import (
@@ -90,20 +91,29 @@
}
// NewClient creates a new gRPC client.
-func NewClient(url *common.URL) *Client {
+func NewClient(url *common.URL) (*Client, error) {
// if global trace instance was set , it means trace function enabled. If not , will return Nooptracer
tracer := opentracing.GlobalTracer()
dialOpts := make([]grpc.DialOption, 0, 4)
maxMessageSize, _ := strconv.Atoi(url.GetParam(constant.MESSAGE_SIZE_KEY, "4"))
- dialOpts = append(dialOpts, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithUnaryInterceptor(
+
+ //consumer config client connectTimeout
+ connectTimeout := config.GetConsumerConfig().ConnectTimeout
+
+ dialOpts = append(dialOpts, grpc.WithInsecure(), grpc.WithBlock(), grpc.WithTimeout(connectTimeout), grpc.WithUnaryInterceptor(
otgrpc.OpenTracingClientInterceptor(tracer, otgrpc.LogPayloads())),
grpc.WithDefaultCallOptions(
grpc.CallContentSubtype(clientConf.ContentSubType),
grpc.MaxCallRecvMsgSize(1024*1024*maxMessageSize),
grpc.MaxCallSendMsgSize(1024*1024*maxMessageSize)))
+
+ logger.Infof("begin grpc dail:%s, begin time: %s ", url, time.Now().Format("2006-01-02 15:04:05.000"))
conn, err := grpc.Dial(url.Location, dialOpts...)
+ logger.Infof("end grpc dail: dail:%s, end time: %s", url, time.Now().Format("2006-01-02 15:04:05.000"))
+
if err != nil {
- panic(err)
+ logger.Errorf("grpc dail error: %v", err)
+ return nil, err
}
key := url.GetParam(constant.BEAN_NAME_KEY, "")
@@ -113,7 +123,7 @@
return &Client{
ClientConn: conn,
invoker: reflect.ValueOf(invoker),
- }
+ }, nil
}
func getInvoker(impl interface{}, conn *grpc.ClientConn) interface{} {
diff --git a/protocol/grpc/client_test.go b/protocol/grpc/client_test.go
index 099f03e..21b81ba 100644
--- a/protocol/grpc/client_test.go
+++ b/protocol/grpc/client_test.go
@@ -18,6 +18,7 @@
package grpc
import (
+ "github.com/apache/dubbo-go/common/logger"
"reflect"
"testing"
)
@@ -48,6 +49,9 @@
url, err := common.NewURL("grpc://127.0.0.1:30000/GrpcGreeterImpl?accesslog=&anyhost=true&app.version=0.0.1&application=BDTService&async=false&bean.name=GrpcGreeterImpl&category=providers&cluster=failover&dubbo=dubbo-provider-golang-2.6.0&environment=dev&execute.limit=&execute.limit.rejected.handler=&generic=false&group=&interface=io.grpc.examples.helloworld.GreeterGrpc%24IGreeter&ip=192.168.1.106&loadbalance=random&methods.SayHello.loadbalance=random&methods.SayHello.retries=1&methods.SayHello.tps.limit.interval=&methods.SayHello.tps.limit.rate=&methods.SayHello.tps.limit.strategy=&methods.SayHello.weight=0&module=dubbogo+say-hello+client&name=BDTService&organization=ikurento.com&owner=ZX&pid=49427&reference.filter=cshutdown®istry.role=3&remote.timestamp=1576923717&retries=&service.filter=echo%2Ctoken%2Caccesslog%2Ctps%2Cexecute%2Cpshutdown&side=provider×tamp=1576923740&tps.limit.interval=&tps.limit.rate=&tps.limit.rejected.handler=&tps.limit.strategy=&tps.limiter=&version=&warmup=100!")
assert.Nil(t, err)
- cli := NewClient(url)
+ cli, err := NewClient(url)
+ if err != nil {
+ logger.Errorf("grpc new client error %v", err)
+ }
assert.NotNil(t, cli)
}
diff --git a/protocol/grpc/grpc_invoker_test.go b/protocol/grpc/grpc_invoker_test.go
index d5ebbb4..0aa6425 100644
--- a/protocol/grpc/grpc_invoker_test.go
+++ b/protocol/grpc/grpc_invoker_test.go
@@ -19,6 +19,7 @@
import (
"context"
+ "github.com/apache/dubbo-go/common/logger"
"reflect"
"testing"
)
@@ -48,8 +49,10 @@
url, err := common.NewURL(mockGrpcCommonUrl)
assert.Nil(t, err)
- cli := NewClient(url)
-
+ cli, err := NewClient(url)
+ if err != nil {
+ logger.Errorf("grpc new client error %v", err)
+ }
invoker := NewGrpcInvoker(url, cli)
args := []reflect.Value{}
diff --git a/protocol/grpc/grpc_protocol.go b/protocol/grpc/grpc_protocol.go
index 3ad1245..db47503 100644
--- a/protocol/grpc/grpc_protocol.go
+++ b/protocol/grpc/grpc_protocol.go
@@ -90,7 +90,12 @@
// Refer a remote gRPC service
func (gp *GrpcProtocol) Refer(url *common.URL) protocol.Invoker {
- invoker := NewGrpcInvoker(url, NewClient(url))
+ client, err := NewClient(url)
+ if err != nil {
+ logger.Warnf("can't dial the server: %s", url.Key())
+ return nil
+ }
+ invoker := NewGrpcInvoker(url, client)
gp.SetInvokers(invoker)
logger.Infof("Refer service: %s", url.String())
return invoker
diff --git a/registry/directory/directory.go b/registry/directory/directory.go
index 8c15240..b6f9322 100644
--- a/registry/directory/directory.go
+++ b/registry/directory/directory.go
@@ -111,7 +111,7 @@
if event == nil {
return
}
- go dir.refreshInvokers(event)
+ dir.refreshInvokers(event)
}
// NotifyAll notify the events that are complete Service Event List.
@@ -370,6 +370,8 @@
newInvoker := extension.GetProtocol(protocolwrapper.FILTER).Refer(newUrl)
if newInvoker != nil {
dir.cacheInvokersMap.Store(key, newInvoker)
+ } else {
+ logger.Warnf("service will be added in cache invokers fail, result is null, invokers url is %+v", newUrl.String())
}
} else {
// if cached invoker has the same URL with the new URL, then no need to re-refer, and no need to destroy
@@ -383,6 +385,8 @@
if newInvoker != nil {
dir.cacheInvokersMap.Store(key, newInvoker)
return cacheInvoker.(protocol.Invoker), true
+ } else {
+ logger.Warnf("service will be updated in cache invokers fail, result is null, invokers url is %+v", newUrl.String())
}
}
return nil, false
diff --git a/test/integrate/dubbo/go-server/go.mod b/test/integrate/dubbo/go-server/go.mod
index 9e11623..53f80ee 100644
--- a/test/integrate/dubbo/go-server/go.mod
+++ b/test/integrate/dubbo/go-server/go.mod
@@ -1,3 +1,8 @@
module github.com/apache/dubbo-go/test/integrate/dubbo/go-server
go 1.13
+
+require (
+ github.com/apache/dubbo-go v1.5.5
+ github.com/apache/dubbo-go-hessian2 v1.9.1
+)