-
Notifications
You must be signed in to change notification settings - Fork 3.9k
there should be 1 source of truth regarding whether a call is cancelled #8409
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
Comments
…8409) It was often inconsistent with call.isCancelled(). Use call.isCancelled() directly instead.
It is redundant and often inconsistent with call.isCancelled(). Use call.isCancelled() directly instead.
It is redundant and often inconsistent with call.isCancelled(). Use call.isCancelled() directly instead.
It is redundant and often inconsistent with call.isCancelled(). Use call.isCancelled() directly instead.
#8411 removes the redundant flag. All tests pass and the example from the linked group post works as expected when using the patched version. |
I think you misunderstand the purpose of Throwing from We would strongly recommend using |
@ejona86 Please have a look at the PR: the |
@ejona86 this statement is currently inaccurate: this is exactly what this bug is about. |
I was purposefully vague when I said "noticed." It depends on your perspective. gRPC noticed the cancellation, but the application hadn't been informed yet via The current behavior is very old. It has the advantage that the application will not be informed of additional messages via That said, looking at your code organization, I see the advantage of having Given the age of this behavior, I'm hesitant to change it even if it produces better results. There is certainly code that has never seen the exception and would begin seeing it with the change... and probably break. But I do see the strong value to new code; cancellation is important. I'll bring this up in an API review meeting on Thursday. To be honest, myself and others have never liked the throwing behavior but it was required. As a general rule we would strongly encourage using
I'm not too concerned about that case, because if you are actually calling |
@ejona86 I usually use
that's a fair point.
great, thanks! |
Yeah, I assumed as much. I just called that out because you argued in part that the exception wasn't matching the value of (Other APIs I would care more about the legalistic argument. But this particular one is quite old and an API wart to begin with.)
Totally agree that onCancelHandler takes plumbing. For your code organization approach I'd probably set a no-op Runnable as the onCancelHandler to disable the exception and then check The main reason I'd want to cause onNext() to throw sooner is so that code that didn't think about cancellation would abort. The runtime exception has its own problems, but I imagine many times it is worked out early in testing/deployment. |
setOnCancelHandler tells gRPC that the application is handling cancellation. But it's fine to have noop behavior within the handler itself if the application doesn't need it. It is just a way to opt-in to the more recent no-exception-from-onNext behavior. Let's mention this use-case in the docs to make it more obvious it is a possibility. Came up as part of grpc#8409.
@ejona86 Nevertheless, i do acknowledge your previous point, that changing the behavior now may break things that were working seamlessly for long time :/ So if you choose to reject my PR because of this, I will just silently cry in some corner where nobody can see, he he ;-) |
In those cases, use Context.addListener(). I will note that your code only looks so clean in dealing with the exception because it isn't observing outbound flow control. To do that you'd need to actually be async to receive the I really wish we had a blocking streaming API to make this sort of thing easier. |
API review meeting notes (from Friday, 8/20/2021):
|
To provide some color to "too dangerous to change," basically you can take the code sample for this issue as an example of code that is likely to be broken by the change. Any code that was blocking to send replies on a streaming RPC (the very case this wants to improve) would never have seen an exception before. |
[silent cry from some dark corner] |
setOnCancelHandler tells gRPC that the application is handling cancellation. But it's fine to have noop behavior within the handler itself if the application doesn't need it. It is just a way to opt-in to the more recent no-exception-from-onNext behavior. Let's mention this use-case in the docs to make it more obvious it is a possibility. Came up as part of #8409.
Uh oh!
There was an error while loading. Please reload this page.
What version of gRPC-Java are you using?
1.39.0
What is your environment?
openJdk-11, ubuntu
What did you expect to see?
StatusRuntimeException
should be thrown consistently byresponseObserver.onNext(...)
ifresponseObserver.isCancelled() == true
What did you see instead?
unless a server dispatches work to other threads, an exception is not thrown by
responseObserver.onNext(...)
regardless ofresponseObserver.isCancelled() == true
.This is due to the fact that there are 2 competing sources on whether a call was cancelled:
responseObserver.isCancelled()
calls call.isCancelled()It seems that observer's additional
cancelled
flag does not bring any value and is completely redundant: I think it should be removed and insteadresponseObserver.onNext()
should be checking cancellation status directly bycall.isCancelled()
the same wayresponseObserver.isCancelled()
does.Steps to reproduce the bug
see https://groups.google.com/g/grpc-io/c/4g9XpeqNngE/m/T_ZqBlWeAQAJ
The text was updated successfully, but these errors were encountered: