Understanding of onError and onComplete on stream connectivity in Bidirectional streaming using grpc-java

13 views Asked by At

I'm trying to understand what happens to a stream when we call onError, onCompleted on client and server side (independently).

My scenario: I have a client where three sender Objects [returned object of calling RPC stub.Function(streamObserver)] have been created and three threads are running parallely to send data using those three objects, server responds back with a OK message to each data sent. Stub functions are called only once during initialisation phase.

My understanding:

  1. Calling RPC/ stubs three times will create three streams in a single channel.
  2. Each stream has two sub streams say upstream from (client to server) and downstream (server to client) and both are independent.

Questions:

  1. what happens when onError is called on server side on one stream. a. both upstream and downstream gets cancelled ? b. only downstream gets cancelled that is server can no longer send responses to client but client can still send messages ? c. what happens when onError is called on client side

  2. same kind of questions with respect to onComplete

I tried each case one by one and below were my observations.. idk if these are expected behaviours or not.

  1. Calling onError:

a. server side after calling onError, tried sending a reply using onNext from server.. it failed and said stream closed but on client side the threads were still trying to send a message and no error was thrown but server was not receiving anything. Same kind of behaviour for onComplete as well.

b. Client side from both ends streams were closed. This I confirmed by trying to send something using onNext on up and down stream, error was thrown saying stream closed

  1. Calling onComplete:

a. server side same behaviour as observed in above 1.a. scenario

b. Client side only upstream was closed, downstream was still open as I received some messages from server after onComplete was called from client side. Error was thrown while trying to send from client to server.

Understanding: calling onError will end both up and down stream.. which is observed in the above observations on both side

but for oncomplete, calling on server side, the upstream was not working and server was not able to received data. Is this the expected behaviour or any fault in the experimentation.

0

There are 0 answers