Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python not able to connect to grpc channel -> "failed to connect to all addresses" "grpc_status":14

I'm getting the error below when trying to call a stub method. Any idea what is causing it?

[bolt.api.handlers] 2019-08-21 20:07:57,792 ERROR handlers:1066: 'ResourceHandler' object has no attribute 'ontology_service_handler'
Traceback (most recent call last):
  File "/bolt-webserver/bolt/api/onse/onse_handlers/ontology_service.py", line 17, in post
    ontology_id = await self.onse_stub.createOntology()
  File "/bolt-webserver/bolt/api/onse/onse_stub.py", line 41, in createOntology
    return self.stub.CreateOntology(ontology_messages_pb2.Ontology())
  File "/usr/local/lib/python3.6/site-packages/grpc/_channel.py", line 565, in __call__
    return _end_unary_response_blocking(state, call, False, None)
  File "/usr/local/lib/python3.6/site-packages/grpc/_channel.py", line 467, in _end_unary_response_blocking
    raise _Rendezvous(state, None, None, deadline)
grpc._channel._Rendezvous: <_Rendezvous of RPC that terminated with:
        status = StatusCode.UNAVAILABLE
        details = "failed to connect to all addresses"
        debug_error_string = "{"created":"@1566418077.791002345","description":"Failed to pick subchannel","file":"src/core/ext/filters/client_channel/client_channel.cc","file_line":3818,"referenced_errors":[{"created":"@1566418077.790965749","description":"failed to connect to all addresses","file":"src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc","file_line":395,"grpc_status":14}]}"

I've tried to provide ip address instead of hostname but still getting the same error . The OnseStub class is initialized right before calling createOntology method. The service is up and running. The failing call is done from a tornado web app (in case that might matter)

class OnseStub:

    def __init__(self, ontology_service_backend):
    self.channel = grpc.insecure_channel('localhost:51051')
    self.stub = ontology_service_pb2_grpc.OntologyServiceStub(self.channel)

    def __del__(self):
    if self.channel != None:
    self.channel.close() # close grpc channel

    async def createOntology(self):
    return self.stub.CreateOntology(ontology_messages_pb2.Ontology())
like image 384
gheorghi evgheniev Avatar asked Aug 21 '19 21:08

gheorghi evgheniev


People also ask

What is a gRPC channel?

A gRPC channel provides a connection to a gRPC server on a specified host and port. It is used when creating a client stub. Clients can specify channel arguments to modify gRPC's default behavior, such as switching message compression on or off. A channel has state, including connected and idle .

What is Python gRPC?

gRPC is an HTTP/2-based Remote Procedure Call (RPC) framework that uses protocol buffers ( protobuf ) as the underlying data serialization framework. It is an alternative to other language-neutral RPC frameworks such as Apache Thrift and Apache Arvo.

What is pb2 in gRPC?

The 2 in pb2 indicates that the generated code is following Protocol Buffers Python API version 2.

Is gRPC concurrent?

A gRPC channel uses a single HTTP/2 connection, and concurrent calls are multiplexed on that connection. When the number of active calls reaches the connection stream limit, additional calls are queued in the client.


2 Answers

What fixed it for me is adding the following option to client channel.

grpc.insecure_channel('localhost:50051', options=(('grpc.enable_http_proxy', 0),))

This is missing in the grpc quickstarts as well and is not really highlighted.

like image 192
Synster Avatar answered Sep 21 '22 12:09

Synster


This is common error, it can occured in different cases. But in most usual case decribed in https://github.com/grpc/grpc/issues/9987 can be fixed by unset http_proxy enviroment variable

if os.environ.get('https_proxy'):
 del os.environ['https_proxy']
if os.environ.get('http_proxy'):
 del os.environ['http_proxy']
like image 33
Ilya Davydov Avatar answered Sep 18 '22 12:09

Ilya Davydov