3

I have developed the gRPC API server via Python, Then build it to container and deploy on Cloud Run,

Which my gRPC server are integrating with TensorFlow application. Actually the tensorflow for image ML, but this is a example code for instance to discuss.

class Calculator(calculator_pb2_grpc.CalculatorServiecer):
    def Calculate(self, request, context):
        try: 
            # Processing
            return #protobuf message    
        except Exception as e:
            logging.error(e)     

def main():
    server = grpc.server(futures.ThreadPoolExecutor(max_workers=10))
    calculator_pb2_grpc.add_CalculatorServiecer_to_server(Calculator(), server)
    server.add_insecure_port('[::]:8080')
    server.start()
    logging.info("Listening on %s.", '8080')
    server.wait_for_termination()

if __name__ == '__main__':
    main() 

But I'm always got error when I calling the gRPC like

gRPC status code 14

ERROR:root:<_InactiveRpcError of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "Socket closed"

ERROR:root:<_InactiveRpcError of RPC that terminated with:
    status = StatusCode.UNAVAILABLE
    details = "Connection reset by peer"

Anyone I have idea? Cause when I testing on localhost everything are worked, even into docker container still can worked, But when everything on Cloud Run has collapse.

Not sure what is the root cause of this problem. It might be keepalive or timeout ?

I try many thing llke at connection channel I change my host name to

 {HOST}:443

Please help, Thank you

Example Client Code

I build the client application as REST API server for calling external gRPC, This REST API server also, deploy on Cloud Run.

CHANNEL = grpc.insecure_channel('<CLOUD_RUN_DOMAIN_WITHOUT_HTTP>:443')
STUB = calculator_pb2_grpc.CalculatorStub(CHANNEL)

@app.get("/add") # passing value via query string
def index_dest(first : float, second : float):
    try:
        res = STUB.Calculate(calculator_pb2.BinaryOperation(first_operand=first,second_operand=second,operation="ADD")) 
        return {"message" : res}
    except Exception as e:
        logging.error(e)
zzob
  • 993
  • 3
  • 9
  • 19

1 Answers1

0

From https://cloud.google.com/run/docs/issues#grpc_websocket:

Cloud Run (fully managed) currently does not support HTTP streaming. Therefore, inbound requests with protocols like WebSockets and gRPC streaming are not supported.

Dustin Ingram
  • 20,502
  • 7
  • 59
  • 82
  • My API server have only uanry service doesn't have any streaming – zzob Aug 25 '20 at 06:03
  • Please post example code on how you call the server. Are you sure the server is up and running correctly? Do you mind trying with another app (maybe deploy the gRPC quickstart sample in grpc.io site)? – ahmet alp balkan Aug 25 '20 at 16:28
  • @AhmetB-Google Do you have any opinion about it? – zzob Aug 29 '20 at 08:47