Automatically detect lingering server calls
- Dominant language
- Java
- Stars
- 12.1k
- Forks
- 4k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 37
Description
### Problem
When subscribing to a server streaming call, it's tedious to set up machinery for canceling the stream when no longer needed.
### Describe the solution you'd like
When a user calls `stub.foo(observer)`, gRPC attaches a [Cleaner](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/lang/ref/Cleaner.html) to it which cancels the corresponding `ClientCallStreamObserver` when the inbound stream observer object becomes unreachable.
Since there is some runtime cost of registering Cleaners for each and every streaming call (and there can be thousands of them at any given time, and an unlimited number in the app lifetime), this may best be an opt-in feature. Not sure about exact API, and whether it should be opt-in per-app, per-method, or per-call.
Adding a cleaner also holds a ref to `ClientCallStreamObserver` as long as the inbound stream observer object is alive in the heap, even if the call itself has completed. We need to make sure this doesn't leak significant resources.
### Describe alternatives you've considered
Per-app opt-in is a form of "debug mode" where lingering connections are logged, and then in prod the machinery may be set-up manually in strategic places.
Contributor guide
Assessment
This issue has not been assessed yet.