question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

there should be 1 source of truth regarding whether a call is cancelled

See original GitHub issue

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 by responseObserver.onNext(...) if responseObserver.isCancelled() == true

What did you see instead?

unless a server dispatches work to other threads, an exception is not thrown by responseObserver.onNext(...) regardless of responseObserver.isCancelled() == true.
This is due to the fact that there are 2 competing sources on whether a call was cancelled:

It seems that observer’s additional cancelled flag does not bring any value and is completely redundant: I think it should be removed and instead responseObserver.onNext() should be checking cancellation status directly by call.isCancelled() the same way responseObserver.isCancelled() does.

Steps to reproduce the bug

see https://groups.google.com/g/grpc-io/c/4g9XpeqNngE/m/T_ZqBlWeAQAJ

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

1reaction
ejona86commented, Aug 17, 2021

in cases that do care about interrupting processing as soon as possible

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 onReady() callback. Not to say flow control actually benefits your code; if you have small CPU-intensive responses it doesn’t do much. My point is just that the situation is more specific than it may appear.

I really wish we had a blocking streaming API to make this sort of thing easier.

1reaction
ejona86commented, Aug 16, 2021

As a matter of fact, I don’t recall using isCancelled() ever before 😉

Yeah, I assumed as much. I just called that out because you argued in part that the exception wasn’t matching the value of isCancelled(). That can be argued from an API-only perspective or from a pragmatic perspective. I was mostly arguing that it doesn’t matter too much to me from a legalese standpoint, as no code should really notice the disagreement and it is easy to workaround. It seemed you were caring about this pragmatically, so it was more “let’s not get sidetracked on the legalistic argument.”

(Other APIs I would care more about the legalistic argument. But this particular one is quite old and an API wart to begin with.)

When all you need is just for the main code to break from the loop, the exception is visibly less hassle.

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 isCancelled() as part of the loop. That’s about as much boilerplate as dealing with the exception. Today you wouldn’t need the no-op Runnable; after your suggested change you would.

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Americans and 'Cancel Culture': Where Some See Calls for ...
Given that cancel culture can mean different things to different people, the survey also asked about the more general act of calling out...
Read more >
What is cancel culture? Why we keep fighting about ... - Vox
Is cancel culture a mob mentality, or a long overdue way of speaking truth to power?
Read more >
Messaging as the Single Source of Truth | Confluent
This concept of notification, via a broker, breaks down complex call graphs, allowing processes to decouple themselves from one another. We ...
Read more >
McConnell criticizes Trump's comments on Constitution - CNN
After days of silence over Trump's call to terminate the Constitution, a number of top Senate Republicans have now condemned the comment. But ......
Read more >
Is Cancel Culture Effective? How Public Shaming Has Changed
Cancel culture is a concept so hotly debated that it remains in limbo, much like many individuals' attitudes toward it.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found