I have defined a bi-dir gRPC streaming RPC for exchanging some configuration information with the server.
Server: Implemented in C++ Client: Implemented in python 3.10
The client opens channel with server using below: grpc.channel_ready_future(self.channel).result(timeout=5)
As and when configuration is changed in the client, it builds the gRPC message and yields the message to server by calling the bi-dir RPC (RPC name "Push"). The client never explicitly closes the channel by calling close. But, as soon as server receives the message, the channel gets reset, so the next message from client uses another channel.
My question is what am I doing wrong in the client and why channel gets closed? One thing is that server actually doesn't send anything back so if I have a for loop as below client code hangs:
responses = self.stub.Push(
make_client_msg(msg),timeout=timeout)
for response in responses:
logging.info("response is {}".format(response))
so I removed for loop and just printing responses, but the channel gets reset:
responses = self.stub.Push(
make_client_msg(msg),timeout=timeout)
logging.info("response is {}".format(responses))
I hope I was able to explain the problem without getting too much into details.
++++++++
Update:
I was able to solve the channel reset issue by creating two subprocess, first sync process builds gRPC message and pushes inside a message queue and second process which is async, reads from the queue and writes the message to gRPC channel in a while loop. I never call done_writing() after writing to gRPC channel which keeps my channel alive and I need not create a new channel for every write which is an expensive operation. I earlier implemented the entire thing using python iterator, but it was sending EOM at the end of iterator which reset my gRPC channel. Not many examples are there around this scenario but thanks for some helpful comments.