6
votes

Quick disclaimer, I am very new to gRPC and RPC in general, so please have patience

I have two gRPC servers running on the same java application, Service A and Service B. Service A creates multiple clients of Service B which then synchronously makes calls to the various instances of Service B

The server

Service A has a rpc call defined by the .proto file as

rpc notifyPeers(NotifyPeersRequest) returns (NotifyPeersResponse);

the server side implementation,

@Override
public void notifyPeers(NotifyPeersRequest request, StreamObserver<NotifyPeersResponse> responseObserver) {
    logger.debug("gRPC 'notifyPeers' request received");
    String host = request.getHost();
    
   
    for (PeerClient c : clients.values()) {   
        c.addPeer(host);    // <----  this call
    }

    NotifyPeersResponse response = NotifyPeersResponse.newBuilder()
            .setResult(result)
            .build();

    responseObserver.onNext(response);
    responseObserver.onCompleted();
}

The list of peers, clients are built up in previous rpc calls.

ManagedChannel channel = ManagedChannelBuilder.forTarget(peer).usePlaintext().build();
ClientB client = new ClientB(channel);
clients.put(peer, client);

The client

rpc addPeer(AddPeerRequest) returns (AddPeerResponse);rpc addPeer(AddPeerRequest) returns (AddPeerResponse);

the server side implementation,

@Override
public void addPeer(AddPeerRequest addPeerRequest, StreamObserver<AddPeerResponse> responseObserver)  {
    logger.info("gRPC 'addPeer' request received");
    boolean result = peer.addPeer(host);
    AddPeerResponse response = AddPeerResponse.newBuilder()
                .setResponse(result)
                .build();
    responseObserver.onNext(response);
    responseObserver.onCompleted();

the client side implementation,

public boolean addPeer(String host) {
    AddPeerRequest request = AddPeerRequest.newBuilder().setHost(host).build();
    logger.info("Sending 'addPeer' request");
    AddPeerResponse response = blockingStub.addPeer(request);
    return response.getResponse();
}

When I run this application, and an RPC is made to Service A and the client connection is created that calls addPeer, an ambiguous exception is thrown, io.grpc.StatusRuntimeException: UNKNOWN which then causes the JVM to shut down. I have no idea how to fix this, or whether it is even possible to create an gRPC client connection within a gRPC server

for all of my gRPC server implementations I'm using blocking stubs.

<grpc.version>1.16.1</grpc.version> <java.version>1.8</java.version>

I've pretty much hit a brick wall, so any information will be appreciated

2
Did you have any luck with this?edubriguenti

2 Answers

1
votes

The UNKNOWN message is an exception on the server side that was not passed to the client. You probably need to increase the log level on the server to try to find the root cause.

In this post here , creating the channel like below, enable it to see a more meaningful error message:

ManagedChannel channel = NettyChannelBuilder.forAddress( host, port )
                .protocolNegotiator(ProtocolNegotiators.serverPlaintext() )
0
votes

If A and B are in the same application have you considered making direct function calls or at least using the InProcessChannelBuilder and InProcessServerBuilder?

As mentioned elsewhere, in the current setup you can try increasing the log level on the server side (in B) to see the source of the exception.