What happened + What you expected to happen
Server app.py
import asyncio
from typing import *
import grpc
import frame_streamer_pb2
import frame_streamer_pb2_grpc
from ray import serve
from ray.serve.drivers import gRPCIngress
import cv2
import numpy as np
import uuid
@serve.deployment(is_driver_deployment=True)
class FrameStreamerServicer(frame_streamer_pb2_grpc.FrameStreamerServicer,
gRPCIngress):
def __init__(self):
self.cameras:Dict[Dict] = {}
def validate_params(self, params:Dict):
#@validation : custom code for authentication
if 5 <= params.fps <= 8 and params.id == 'camera_1':
return True
else:
return False
async def ConnectCamera(self, request, context):
params = request
print(request)
if self.validate_params(params):
id = str(uuid.uuid4())
self.cameras[id] = params
return frame_streamer_pb2.ConnectResponse(success=True, message=id)
else:
return frame_streamer_pb2.ConnectResponse(success=False, message='failed')
entrypoint = FrameStreamerServicer.bind()
client.py
'@author:NavinKumarMNK'
import grpc
import cv2
import time
import numpy as np
import frame_streamer_pb2
import frame_streamer_pb2_grpc
import os
async def run(camera:int, id:str='camera_1', fps:int=5):
"""
@brief : Connect to server and send frames through gRPC channel
@args : camera int : Camera value
id str : Camera name
fps int : Frames per second
@return: None
"""
channel = grpc.aio.insecure_channel('172.17.0.2:9000')
stub = frame_streamer_pb2_grpc.FrameStreamerStub(channel)
camera_params = frame_streamer_pb2.CameraParams(
id='camera_1',
fps=5
)
response = stub.ConnectCamera(camera_params)
print(await response.details())
if response[0].success == True:
print('Connected to camera successfully')
elif response[0].success == False:
print('Failed to connect to camera')
return
if __name__ == '__main__':
import asyncio
asyncio.run(run(
camera=0,
id="camera_1",
fps=5
))
Simple grpc communication through ray serve
Expected:
To receive the message
Error:
failed to connect to all addresses; last error: UNKNOWN: ipv4:172.17.0.2:9000: Failed to connect to remote host: Connection refused
Traceback (most recent call last):
File "/home/mnk/client/client.py", line 73, in <module>
asyncio.run(run(
File "/home/mnk/python3/envs/pytorch/lib/python3.10/asyncio/runners.py", line 44, in run
return loop.run_until_complete(main)
File "/home/mnk/python3/envs/pytorch/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
return future.result()
File "/home/mnk/client/client.py", line 56, in run
if response[0].success == True:
TypeError: 'UnaryStreamCall' object is not subscriptable
if
channel = grpc.insecure_channel('172.17.0.2:9000') #replaced instead
print(list(response))
Error:
Traceback (most recent call last):
File "/home/mnk/client/client.py", line 72, in <module>
run(
File "/home/mnk/client/client.py", line 53, in run
print(list(response))
File "/home/mnk/python3/envs/pytorch/lib/python3.10/site-packages/grpc/_channel.py", line 426, in __next__
return self._next()
File "/home/mnk/python3/envs/pytorch/lib/python3.10/site-packages/grpc/_channel.py", line 826, in _next
raise self
grpc._channel._MultiThreadedRendezvous: <_MultiThreadedRendezvous of RPC that terminated with:
status = StatusCode.UNAVAILABLE
details = "failed to connect to all addresses; last error: UNAVAILABLE: ipv4:172.17.0.2:9000: Failed parsing HTTP/2"
debug_error_string = "UNKNOWN:failed to connect to all addresses; last error: UNAVAILABLE: ipv4:172.17.0.2:9000: Failed parsing HTTP/2 {created_time:"2023-05-14T19:53:07.086624691+05:30", grpc_status:14}"
Failed to parse HTTP/2
Note: I ran the exact same program in Experimental Direct Ingress — Ray 2.4.0 : use Serve schema
i got same error
Versions / Dependencies
Ray 2.4.0
python - 3.8.10
grpcio - 1.51.3
protobuf - 3.20.3
OS : ubuntu 22.04
Mention:
Server is in Docker Container
Client in my Laptop
Reproduction script
$ serve run app:entrypoint --host 172.17.0.2 --port 9000
$ python3 client.py
Issue Severity
High: It blocks me from completing my task.