nacos-group / nacos-sdk-go

Nacos client in Golang

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

grpc通过endpoint连接服务端失败

DSSLP opened this issue · comments

What version of nacos-sdk-go are you using?

2.2.2

What version of nacos-sever are you using?

2.2.2

What version of Go are you using (go version)?

go1.21.0

What operating system (Linux, Windows, …) and version?

Linux

What did you do?

If possible, provide a recipe for reproducing the error.
使用endpoint访问nacos集群,客户端定时访问endpoint获取nacos ip列表,进而直连ip

What did you expect to see?

成功连接

What did you see instead?

image
连接失败,检查发现,grpcport为0,定位发现refreshServerSrvIfNeed时,生成的ServerConfig没有携带grpcport
image

endpoint 中要配置port

endpoint 中要配置port

不是这个意思,我这边已经正确拿到了nacos的集群ip,在构建serverconfig的时候,sdk里赋值了port为8848,但是grpcport值并没有赋值,按道理应该是8848+1000得到的,所以报错信息里显示连接nacos服务端时grpcport为0

endpoint 中要配置port

不是这个意思,我这边已经正确拿到了nacos的集群ip,在构建serverconfig的时候,sdk里赋值了port为8848,但是grpcport值并没有赋值,按道理应该是8848+1000得到的,所以报错信息里显示连接nacos服务端时grpcport为0

默认会对port+1000 作为grpc port

func (c *GrpcClient) createNewConnection(serverInfo ServerInfo) (*grpc.ClientConn, error) {
	var opts []grpc.DialOption
	opts = append(opts, grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(getMaxCallRecvMsgSize())))
	opts = append(opts, grpc.WithKeepaliveParams(getKeepAliveTimeMillis()))
	opts = append(opts, grpc.WithInsecure())
	opts = append(opts, grpc.WithInitialWindowSize(getInitialWindowSize()))
	opts = append(opts, grpc.WithInitialConnWindowSize(getInitialConnWindowSize()))
	rpcPort := serverInfo.serverGrpcPort
	if rpcPort == 0 {
		rpcPort = serverInfo.serverPort + c.rpcPortOffset()
	}
	return grpc.Dial(serverInfo.serverIp+":"+strconv.FormatUint(rpcPort, 10), opts...)

} 
createNewConnection

明白了,这块的日志能不能改善一下呢?

createNewConnection

明白了,这块的日志能不能改善一下呢?

欢迎提交pr进行优化