0
votes

I have a grpc Nodejs server behind a HAproxy and client-streaming rpc java maven.

When I run the java client it return an error:

io.grpc.StatusRuntimeException: UNAVAILABLE: HTTP status code 503 invalid content-type: text/html headers: Metadata(:status=503,cache-control=no-cache,content-type=text/html) DATA-----------------------------

503 Service Unavailable No server is available to handle this request.

I already test a rpc client streaming with Nodejs and it worked.

My java client code:

public class App {
    public static void main(String[] args) throws InterruptedException {
        WebRTCStats stat = WebRTCStats.newBuilder().setUserId("abc").build();
        SendWebRTCStats(stat);
    }

    public static void SendWebRTCStats(WebRTCStats stat) throws InterruptedException {
        ManagedChannel channel = ManagedChannelBuilder.forTarget("example.com:443").useTransportSecurity()
                .build();
        ClientGrpc.ClientStub stub = ClientGrpc.newStub(channel);

        StreamObserver<Stat.Status> responseObserver = new StreamObserver<Stat.Status>() {
            @Override
            public void onNext(Stat.Status status) {

            }

            @Override
            public void onError(Throwable t) {
                t.printStackTrace();
            }

            @Override
            public void onCompleted() {
                System.out.print("complete");
            }
        };
        StreamObserver<WebRTCStats> requestObserver = stub.sendWebRTCStats(responseObserver);
        try {
            // Send numPoints points randomly selected from the features list.

            requestObserver.onNext(stat);
            // Sleep for a bit before sending the next one.

        } catch (RuntimeException e) {
            // Cancel RPC
            requestObserver.onError(e);
            throw e;
        }
        // Mark the end of requests
        requestObserver.onCompleted();

        // Receiving happens asynchronously

    }
}

My NodeJS server:

const PROTO_PATH = './stat.proto';
const grpc = require('grpc');
const protoLoader = require('@grpc/proto-loader');
const fs = require('fs');
const tcp = require('./using.js');

let packageDefinition = protoLoader.loadSync(PROTO_PATH);

let protoDescriptor = grpc.loadPackageDefinition(packageDefinition);

const server = new grpc.Server();


server.addService(protoDescriptor.Client.service, {
    SendWebRTCStats: async (call, callback) => {
        call.on('data', value => {
            console.log(value);
            tcp.sendLog("test", value);
        });

        call.on('end', () => {
            callback(null, { status: 'success' });
        })
    },
});

let credentials = grpc.ServerCredentials.createSsl(
    fs.readFileSync('ca.cer'), [{
    cert_chain: fs.readFileSync('cer.crt'),
    private_key: fs.readFileSync('cer_key.key')
}], false);

server.bind("0.0.0.0:443", credentials);
console.log("Server running at 443");
server.start();

Can this problem occurs by different implementations of different libraries of language in GRPC?

1
The problem has nothing to do with the client. You're using a proxy, and something is wrong with the proxy or backend. - Eric Anderson
@EricAnderson i see , i am trying to troubleshoot haproxy. but i connected through the proxy to nodejs server by nodejs client just fine. it's just the java client that dead. - Nguyễn Hoàng Hưng

1 Answers

0
votes

so apperently i changed forTarget("example.com) and it worked. I shouldnt specify port for it.