Hi,
I'm trying to find what the proper reaction to ok == false should be in asynchronous API with streaming responses. I can't infer it from the documentation.
This is my understanding of the state machine allowing to properly read a whole stream of responses (please correct me if I'm wrong).
The stream can be in one of the following states:
- NOT_CREATED (before we touch anything)
- CREATING (after calling Stub::AsyncFoo(), before CompletionQueue::AsyncNext() reports completion)
- PROCESSING (after calling ClientAsyncReaderInterface<>::Read())
- FINISHING (after calling calling ClientAsyncReaderInterface<>::Finish(), before CompletionQueue::AsyncNext() reports completion)
- FINISHED (the stream is dead, all resources are freed)
These are the transitions between the states:
State NOT_CREATED:
- Calling Stub::AsyncFoo() transitions to CREATING
State
CREATING:
- if CompletionQueue::AsyncNext() sets ok to true, call ClientAsyncReaderInterface<>::Read() and transition to PROCESSING; (we just got a response, BTW)
- if CompletionQueue::AsyncNext() sets ok to false, call ClientAsyncReaderInterface<>::Finish() transition to FINISHING
State PROCESSING:
- if CompletionQueue::AsyncNext() sets ok to true, call ClientAsyncReaderInterface<>::Read() and transition to PROCESSING
- if CompletionQueue::AsyncNext() sets ok to false, call ClientAsyncReaderInterface<>::Finish() and transition to FINISHING
- when CompletionQueue::AsyncNext() notifies (it will always set `ok == true`) transition to FINISHED; (here we learn if the stream was just closed or if there was an error)
State
FINISHED:
I have a couple of questions:
- Is this a understanding correct?
- If I wanted to finish the stream in the client, I presume, I can call Finish() in CREATING and PROCESSING states, right?
- Is this the same state machine on the server side or if streaming in the other direction?
The reason I'm asking is that I'm getting a grpc assertion when calling Finish() after having received ok == false in state PROCESSING:
grpc/src/core/lib/surface/call.cc:1853: grpc_cq_begin_op(call->cq, notify_tag)
I'd be grateful for clarification, because I'm currently don't know if I'm misusing the library or I have a bug.
Thanks in advance