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)