Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grpc通过endpoint连接服务端失败 #678

Open
DSSLP opened this issue Nov 8, 2023 · 5 comments
Open

grpc通过endpoint连接服务端失败 #678

DSSLP opened this issue Nov 8, 2023 · 5 comments

Comments

@DSSLP
Copy link

DSSLP commented Nov 8, 2023

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

@DSSLP DSSLP changed the title grpc连接服务端失败 grpc通过endpoints连接服务端失败 Nov 8, 2023
@DSSLP DSSLP changed the title grpc通过endpoints连接服务端失败 grpc通过endpoint连接服务端失败 Nov 8, 2023
@binbin0325
Copy link
Member

endpoint 中要配置port

@DSSLP
Copy link
Author

DSSLP commented Nov 8, 2023

endpoint 中要配置port

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

@binbin0325
Copy link
Member

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...)

} 

@DSSLP
Copy link
Author

DSSLP commented Nov 9, 2023

createNewConnection

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

@binbin0325
Copy link
Member

createNewConnection

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

欢迎提交pr进行优化

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants