title: grpc._channel._InactiveRpcError: <_InactiveRpcError of RPC that terminated with: status = StatusCode.UNAVAILABLE
body: <p>I have written a simple GRPC service, client code in python. Sometimes out of nowhere, the client fails with the following error:</p>
  <pre><code>Traceback (most recent call last):
    File &quot;grpc_client.py&quot;, line 35, in &lt;module&gt;
      response = stub.YOLO_frame(image_req)
    File &quot;/home/vmuser/anaconda3/envs/lp_reg_brta/lib/python3.7/site-packages/grpc/_channel.py&quot;, line 923, in __call__
      return _end_unary_response_blocking(state, call, False, None)
    File &quot;/home/vmuser/anaconda3/envs/lp_reg_brta/lib/python3.7/site-packages/grpc/_channel.py&quot;, line 826, in _end_unary_response_blocking
      raise _InactiveRpcError(state)
  grpc._channel._InactiveRpcError: &lt;_InactiveRpcError of RPC that terminated with:
          status = StatusCode.UNAVAILABLE
          details = &quot;failed to connect to all addresses&quot;
          debug_error_string = &quot;{&quot;created&quot;:&quot;@1613478605.328638006&quot;,&quot;description&quot;:&quot;Failed to pick subchannel&quot;,&quot;file&quot;:&quot;src/core/ext/filters/client_channel/client_channel.cc&quot;,&quot;file_line&quot;:5390,&quot;referenced_errors&quot;:[{&quot;created&quot;:&quot;@1613478605.328628806&quot;,&quot;description&quot;:&quot;failed to connect to all addresses&quot;,&quot;file&quot;:&quot;src/core/ext/filters/client_channel/lb_policy/pick_first/pick_first.cc&quot;,&quot;file_line&quot;:397,&quot;grpc_status&quot;:14}]}&quot;
  &gt;
  </code></pre>
  <p>My server:</p>
  <pre><code>import grpc
  from concurrent import futures
  import time
  
  import darknet
  
  # import the generated classes
  import lp_reg_pb2
  import lp_reg_pb2_grpc
  
  
  
  # based on .proto service
  class LP_REGServicer(lp_reg_pb2_grpc.LP_REGServicer):
      def YOLO_frame(self, request, context):
          response = lp_reg_pb2.PredictionBBox()
          # print(type(request.b64_frame))
  
  
          response.class_labels.extend([1])
          response.xc.extend([1])
          response.yc.extend([1])
          response.w.extend([1])
          response.h.extend([1])
          
          # darknet.dummy_predict_grpc(request.b64_frame)
          return response
  
      def YOLO_lp(self, request, context):
          response = lp_reg_pb2.LPBBox()
          response.class_labels.extend([1])
          response.xc.extend([1])
          response.yc.extend([1])
          response.w.extend([1])
          response.h.extend([1])
          return response
  
  # create a gRPC server
  server = grpc.server(futures.ThreadPoolExecutor(max_workers=12))
  
  
  # add the defined class to the server
  lp_reg_pb2_grpc.add_LP_REGServicer_to_server(
          LP_REGServicer(), server)
  
  # listen on port 5005
  print('Starting server. Listening on port 5005.')
  server.add_insecure_port('[::]:5005')
  server.start()
  
  try:
      while True:
          time.sleep(5)
  except KeyboardInterrupt:
      server.stop(0)
  </code></pre>
  <p>My client code:</p>
  <pre><code>import grpc
  
  # import the generated classes
  import lp_reg_pb2
  import lp_reg_pb2_grpc
  
  # data encoding
  
  import numpy as np 
  import base64
  import zlib
  import time
  import cv2
  
  # open a gRPC channel
  channel = grpc.insecure_channel('127.0.0.1:5005')
  
  # create a stub (client)
  stub = lp_reg_pb2_grpc.LP_REGStub(channel)
  
  # encoding image/numpy array
  
  t1 = time.time()
  for _ in range(10):
      frame = cv2.resize( cv2.imread('prediction.jpg'), (416, 416) ) # dummy rgb image
  
      img_encoded = cv2.imencode('.jpg', frame)[1]
  
      img_bytes = img_encoded.tobytes()  # bytes class
  
      # create a valid request message
      image_req = lp_reg_pb2.B64Frame(b64_frame = img_bytes)
  
      # make the call
      response = stub.YOLO_frame(image_req)
      print(response)
  t2 = time.time()
  
  print(f&quot;time: {(t2-t1)/10.}&quot;)
  </code></pre>
  <p>I tried adding <code>channel.close()</code> in the client code but it still throws this error without any proper response.</p>
  <ul>
  <li>The client works after I change the port, but after a while, I get this error again.</li>
  </ul>