0

After deploying my server on Cloud Run, calling the endpoint with BloomRPC or other clients, the service returns "error": "2 UNKNOWN: No status received". Calling the server locally with PORT=7000 node index.js on localhost:7000 works fine. I guess Cloud Run is adding some TLS magic somewhere and maybe resets the headers but I have no idea how to fix that.

Here's my code:

const grpc = require("@grpc/grpc-js");
const protoLoader = require('@grpc/proto-loader');

const reportGenProto = protoLoader.loadSync("reportGen.proto");
const packageObject = grpc.loadPackageDefinition(reportGenProto);

const server = new grpc.Server();
server.addService(packageObject.ReportGeneratorService.service, {
    Ping: async function (call, callback) {
        console.log("PONG");
        callback(null, {
            pong: "pong"
        });
    },
});

server.bindAsync(`0.0.0.0:${process.env.PORT}`, grpc.ServerCredentials.createInsecure(), (err) => {
    if (err) throw err;
    console.log('Server running on port', process.env.PORT);
    server.start();
});

And this is the .proto:

syntax = "proto3";

service ReportGeneratorService {
  rpc Ping (Empty) returns (Pong) {}
}

message Pong {
  string pong = 1;
}

message Empty {}

Cloud Run logs don't say anything other than that console.log("PONG"). I've tried enabling HTTP/2 even though I'm not using streams but the same thing is returned.

I'm building and deploying inside a Docker container, as I need some dependencies for what I'll do later with the server. This is the Dockerfile:

# we just need the LibreOffice environment to convert the file, this we'll do
FROM ideolys/carbone-env-docker

ENV DIR /app
WORKDIR ${DIR}
COPY . ${DIR}
RUN npm install
ENV TZ Europe/Rome

CMD [ "node", "index.js" ]

I'm also adding that using the deprecated gRPC node package works fine without changing anything in the configuration. The problem happens only when using the new grpc-js package.

antipopp
  • 409
  • 1
  • 3
  • 14

1 Answers1

1

I repro'd your solution (code unchanged) and it works for me.

{
    "name": "72141720",
    "version": "0.0.1",
    "scripts": {
      "start": "node index.js"
    },
    "dependencies": {
        "@grpc/grpc-js": "^1.6.7",
        "@grpc/proto-loader":"^0.6.12"
    }
}

And:

BILLING=
PROJECT=
REGION=
SERVICE=

gcloud projects create ${PROJECT}

gcloud beta billing projects link ${PROJECT} \
--billing-account=${BILLING}

for SERVICE in "artifactregistry" "cloudbuild" "run"
do
  gcloud services enable ${SERVICE}.googleapis.com \
  --project=${PROJECT}
done

# Deploy from source
gcloud run deploy ${SERVICE} \
--source=${PWD} \
--project=${PROJECT} \
--region=${REGION}

# Determine service endpoint
# Remove "https://"
# Add ":443"
ENDPOINT=$(\
  gcloud run services describe ${SERVICE} \
  --project=${PROJECT} \
  --region=${REGION} \
  --format="value(status.Url)") && \
ENDPOINT="${ENDPOINT#https://}:443"

# gRPCurl it
# https://github.com/fullstorydev/grpcurl
grpcurl \
-proto ./reportGen.proto \
${ENDPOINT} \
ReportGeneratorService/Ping

Yields:

{
  "pong": "pong"
}
DazWilkin
  • 32,823
  • 5
  • 47
  • 88
  • This is working! But I'm so sorry, I forgot to add that I was building and deploying inside a Docker container. I'll update the question with the Dockerfile I'm using. At this point I think this is the problem. – antipopp May 07 '22 at 09:19
  • I concur. I built the image using your `Dockerfile` and ran it locally and I'm unable to gRPCurl the endpoint. The base image of the container (`ideolys/carbone-env-docker`) is opaque (unpublished?) so I can't help further. – DazWilkin May 07 '22 at 17:14
  • The image is published on Github (https://github.com/carboneio/carbone-env-docker). I don't really know much about Docker, but I don't see anything particular in the image Dockerfile. Maybe I'll open an issue there as it's the image advised by the service I want to use. – antipopp May 09 '22 at 07:47