0

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 Nov 10 '20 at 18:49
  • @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 Nov 11 '20 at 02:47

1 Answers1

0

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

  • That would change the value of the Host header in the HTTP request sent. It sounds like you need to configure your proxy to allow the port to be specified for virtual hosting. Removing the port is fine, but the fact it mattered means you should fixup some proxy configuration. – Eric Anderson Nov 12 '20 at 15:22
  • @EricAnderson thanks for your information. So that's how it worked. I didnt know how the abstraction is implemented. – Nguyễn Hoàng Hưng Nov 13 '20 at 07:42