-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ClientOnlyStream.receiveAndClose(): Cancellation Exception occurring #100
Comments
Sorry for the delay - I'll be taking a look at this today. What type of server are you interfacing with when you see this behavior? (i.e. connect-go, grpc-go, grpc-java) |
connect-go |
I believe what is happening is that it doesn't receive the result in a timely enough manner, as the backend awaits a push notification for the photo URL, and then it hits the finally block and cancels, causing this crash, as the receive channel is still open awaiting a result. It always does process the result, so that's the upside, it's just that it crashes my application sometimes. Initially when implementing this, I could not get my server to provide the URL in its history. The result is not used immediately, it is used later on with a history request. That was when I was just calling close() and not close() then receiveAndClose(). |
Awesome, fix looks great! That should absolutely take care of my issues. Thank you! |
Update conformance tests to add a new test exercising client side streaming, which exposed several issues in streaming call implementations. The first issue only affected client streaming (it stopped attempting to read a response from the server once the send side closed - it should have stopped only if the receive side closed). The second issue resulted from not calling close on the channel after the completion message was received, which lead to hangs consuming from `resultChannel()` (it would never complete). After this fix, both examples (for java and javalite) were updated and fixed to correctly exit when finished. Additionally, several cleanups were made to the API (since the current API for client streaming was non-functional - it would only return the initial Headers result and not the message or completion result). This should help resolve reported streaming issues like #100. # API Updates ## `com.connectrpc.BidirectionalStreamInterface` ### Removed * `close()` * Use `sendClose()` instead. This may have confused callers that the close() method would close both send and receive sides of the connection when it was only closing the send side. ## `com.connectrpc.ClientOnlyStreamInterface` ### Added * `sendClose()` * This shouldn't typically need to be called as receiveAndClose() already closes the send side of the stream. * `isSendClosed()` ### Changed * `receiveAndClose()` * Changed to return a ResponseMessage instead of a StreamResult. This allows callers to easily get access to the response as if they were calling a unary method. Previously, the StreamResult would only return the first result retrieved by the call, which typically was a Headers result (leaving callers unable to access the Message or Completion contents). ### Removed * `close()` * Replaced with `sendClose()`. ## `com.connectrpc.ServerOnlyStreamInterface` ### Added * `receiveClose()` * `isReceiveClosed()` ### Removed * `close()` * This closed both the send and receive side of the stream (unlike in other interfaces which just closed the send side). If needed, callers should invoke `receiveClose()` instead (although this isn't necessary in normal use). * `send()` * Callers should invoke `sendAndClose()` instead. Otherwise, reading results from `resultChannel()` will hang since the send side of the stream should be closed before reading responses. ## `com.connectrpc.StreamResult` ### Removed * Removed the `error` field from the base `StreamResult` class. It was never used by the `Headers` or `Message` subclasses and only used on the `Complete` type. This should make it easier for callers to use `Headers` and `Message` types since they don't need to worry about handling `error`.
connect-kotlin v0.2.0 is now available with several fixes to streaming (including client streaming). Can you give the new release a try and let me know if it resolves the issues on your side? |
Confirmed this is now working. Closing issue. |
I'm getting a crash calling this function, occasionally, it doesn't occur every time but it occurs about ⅓ of the time. It seems that if the function doesn't return the resultChannel.receive() in a timely manner, it hits the finally block and cancels the resultChannel, throwing the below exception. Also, shouldn't this function close the messageStream after receiving the result? I have to call the close() function before calling the receiveAndClose() function, otherwise my client doesn't receive from the result channel and my backend service does not process the resulting stream I sent to it. Thanks for looking into this!
Here is my client code:
The text was updated successfully, but these errors were encountered: