diff --git a/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java b/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java index e26d14b4e5c..f21bf52a5f3 100644 --- a/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java +++ b/common/src/main/java/com/alibaba/nacos/common/remote/client/grpc/GrpcClient.java @@ -330,40 +330,36 @@ public Connection connectToServer(ServerInfo serverInfo) { int port = serverInfo.getServerPort() + rpcPortOffset(); ManagedChannel managedChannel = createNewManagedChannel(serverInfo.getServerIp(), port); RequestGrpc.RequestFutureStub newChannelStubTemp = createNewChannelStub(managedChannel); - if (newChannelStubTemp != null) { - - Response response = serverCheck(serverInfo.getServerIp(), port, newChannelStubTemp); - if (response == null || !(response instanceof ServerCheckResponse)) { - shuntDownChannel(managedChannel); - return null; - } - - BiRequestStreamGrpc.BiRequestStreamStub biRequestStreamStub = BiRequestStreamGrpc.newStub( - newChannelStubTemp.getChannel()); - GrpcConnection grpcConn = new GrpcConnection(serverInfo, grpcExecutor); - grpcConn.setConnectionId(((ServerCheckResponse) response).getConnectionId()); - - //create stream request and bind connection event to this connection. - StreamObserver payloadStreamObserver = bindRequestStream(biRequestStreamStub, grpcConn); - - // stream observer to send response to server - grpcConn.setPayloadStreamObserver(payloadStreamObserver); - grpcConn.setGrpcFutureServiceStub(newChannelStubTemp); - grpcConn.setChannel(managedChannel); - //send a setup request. - ConnectionSetupRequest conSetupRequest = new ConnectionSetupRequest(); - conSetupRequest.setClientVersion(VersionUtils.getFullClientVersion()); - conSetupRequest.setLabels(super.getLabels()); - conSetupRequest.setAbilities(super.clientAbilities); - conSetupRequest.setTenant(super.getTenant()); - grpcConn.sendRequest(conSetupRequest); - //wait to register connection setup - Thread.sleep(100L); - return grpcConn; + Response response = serverCheck(serverInfo.getServerIp(), port, newChannelStubTemp); + if (!(response instanceof ServerCheckResponse)) { + shuntDownChannel(managedChannel); + return null; } - return null; + + BiRequestStreamGrpc.BiRequestStreamStub biRequestStreamStub = BiRequestStreamGrpc.newStub( + newChannelStubTemp.getChannel()); + GrpcConnection grpcConn = new GrpcConnection(serverInfo, grpcExecutor); + grpcConn.setConnectionId(((ServerCheckResponse) response).getConnectionId()); + + //create stream request and bind connection event to this connection. + StreamObserver payloadStreamObserver = bindRequestStream(biRequestStreamStub, grpcConn); + + // stream observer to send response to server + grpcConn.setPayloadStreamObserver(payloadStreamObserver); + grpcConn.setGrpcFutureServiceStub(newChannelStubTemp); + grpcConn.setChannel(managedChannel); + //send a setup request. + ConnectionSetupRequest conSetupRequest = new ConnectionSetupRequest(); + conSetupRequest.setClientVersion(VersionUtils.getFullClientVersion()); + conSetupRequest.setLabels(super.getLabels()); + conSetupRequest.setAbilities(super.clientAbilities); + conSetupRequest.setTenant(super.getTenant()); + grpcConn.sendRequest(conSetupRequest); + //wait to register connection setup + Thread.sleep(100L); + return grpcConn; } catch (Exception e) { - LOGGER.error("[{}]Fail to connect to server!,error={}", GrpcClient.this.getName(), e); + LOGGER.error("[{}]Fail to connect to server!", GrpcClient.this.getName(), e); } return null; }