Il server API gRPC tramite Python non può funzionare

Aug 25 2020

Ho sviluppato il server API gRPC tramite Python, quindi lo costruisco nel container e lo distribuisco su Cloud Run,

Che il mio server gRPC si sta integrando con l'applicazione TensorFlow. In realtà il tensorflow per l'immagine ML, ma questo è un codice di esempio da discutere ad esempio.

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() 

Ma ho sempre un errore quando chiamo gRPC come

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"

Qualcuno che ho idea? Perché quando eseguo il test su localhost tutto funziona, anche nel contenitore docker può ancora funzionare, ma quando tutto su Cloud Run è crollato.

Non sono sicuro di quale sia la causa principale di questo problema. Potrebbe essere keepalive o timeout?

Provo molte cose come nel canale di connessione in cui cambio il mio nome host

 {HOST}:443

Per favore aiutatemi, grazie

Esempio Codice Cliente

Costruisco l'applicazione client come server API REST per chiamare gRPC esterno, anche questo server API REST, distribuisce su 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)

Risposte

DustinIngram Aug 25 2020 at 11:04

Dahttps://cloud.google.com/run/docs/issues#grpc_websocket:

Cloud Run (completamente gestito) attualmente non supporta lo streaming HTTP. Pertanto, le richieste in entrata con protocolli come WebSockets e streaming gRPC non sono supportate.