-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
How to cancel a GRPC Server streaming call #3095
Comments
@varshanbp I think you need to call |
@fanminshi I use "Server-side streaming RPC". I want to close the channel from client. If I shutdown channel from client, it throws error in Server and keeps returning value to closed channel. How to solve this problem? I want to close a channel from Client properly. |
@varshanbp wants to shut down the stream from the client side, this example shuts it down from the server side @fanminshi |
@conorgriffin oops. wrong example. I meant to show this one. you probably don't want to kill channel right away. maybe follow the example here to properly shutdown channel. public void shutdown() throws InterruptedException {
channel.shutdown().awaitTermination(5, TimeUnit.SECONDS);
} |
@varshanbp In the future, this kind of question would be better posted on Stack Overflow or the mailing list. To answer your question: You can cancel a call on the client by calling If you want a more graceful shutdown, you can modify your streaming RPC to just make Note that |
@carl-mastrangelo, the client can't call It'd be a good API to add to |
@ejona86 another way to cancel server-streaming calls or unary calls from client side is using an interceptor, and call |
We've been trying to find a solution for canceling unary calls a few months ago. We found that unary calls are uncancelable by design ("unary calls should provide enough information to the server to make the server cancel properly" - sorry, can't find the quote now as I'm on mobile, but it comes from grpc devs). Since then we've been marking all our cancelable unary calls as streaming (while documenting the intent). |
No, they should be cancellable. It is important that they can be cancelled on-demand by the client. That is non-negotiable (it's been argued before), so if you'd like me to argue with another dev I can :)
Yeah, that doesn't really help anyone. Unary RPCs are much easier to use in most languages. |
Yeah, you're right, sorry. I found the quote: grpc/grpc#8023 (comment). Apparently I misread that / misremember that.
which basically says what you're saying. And yet at the time of testing this (in February) we did not find a working solution in Java/node.js. I'll try again with the context stuff you mentioned. Still this sucks more than it should. Thanks for clearing this up, it actually makes gRPC looks good to me again. We wrote a whole machinery around these cancallable server-streaming calls, and I'm looking forward to deleting it all. (EDIT: Removed some wrong assumptions. I don't remember things correctly after 5 months of not working with this anymore.) |
Agreed. But on the bright side #3115 is merged and will be available in 1.6. Also, using ClientCall directly isn't that bad and isn't too different than the StreamObserver, so that's another short-term option. It's in the Context documentation, but when making your own CancellableContext, make sure you cancel it when done with it (in the success case). |
Am i right, that there is no way to cancel using the auto-generated stubs (Java) !? |
@jzillmann you can use io.grpc.Context to cancel any stub type. For blocking you can interrupt the thread; for future you can cancel the future; for async you can use |
I made a Call to server. The server streams. I want to cancel the call from client.
How to cancel? No Method to cancel a call.
The text was updated successfully, but these errors were encountered: