-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
proposal: add CallOption that sets callback on stream close event #1717
Comments
For the client side of streaming RPCs, unfortunately things like this are not straightforward.
|
Ok i agree with you. Mb logic can be similar to |
EDIT: see below |
FWIW, I have been implementing this sort of clean-up by wrapping the client-stream and then calling the hook from either of two places:
Some sort of synchronizer ( The second bullet handles the case where the client never exhausts the response stream. Yes, I know it is not pretty. But I haven't found any other way to know with certainty that a client stream is over. |
We had this same thought a few months ago when the issue of ... And now I believe my comment on Dec 14 is bad:
This has the same drawbacks as just wrapping the |
Closing due to lack of activity and priority. |
Isn't this similar to the internal issue for which @greg-dennis filed #4379. If we plan on not adding support for this in the near future, how about adding an example which uses one of the two methods (or both) described in this thread? |
My issue #4379 is a bit more narrowly tailored to just the case of wanting to cancel a context when streaming is done, not an arbitrary callback. Such a CallOption would make the same level of guarantee (or lack thereof) of any other call option that has an "after" effect. If this is not acceptable, we could perhaps tailor it even further to my particular use case of wanting to inject a default timeout by creating a new child context. |
If we can have a |
I still don't think us doing anything here is likely, and it doesn't come up that often. An interceptor can do this, it's just tricky. There are rules documented that applications are expected to follow that interceptors can rely upon:
The trickiest one here is (1), which would require intercepting (wrapping) (2) requires a goroutine for the stream, which is unfortunate, but manageable. And, in the case of #4379, wouldn't be necessary due to cancelation propagation. At this point I don't see this feature ever becoming a high enough priority. |
My takeaway seems to be that if a The other alternatives seem baroque and not fundamentally different in terms of their guarantees. Let me know if you believe that conclusion to be incorrect. |
As a general philosophy, this doesn't sound like a good idea. The application may be using a context that persists for the duration of the process, and it may be performing millions of RPCs during that time. This kind of scenario would result in leaked contexts.
If the client doesn't use the stream properly, there is already a goroutine / memory leak. So you can rely on the application following these rules, or if it doesn't, you won't be making anything substantially worse. (In fact, it would be better as your shorter deadlines would actually clean up the leaks.)
If you are in full control of the application that is using the interceptors, then the decision is ultimately up to you. If you are writing an interceptor to be used by applications outside your control, then my recommendation is to cancel the contexts you create when |
It will be very usefull, if i can set some callback, witch will be called when grpc stream is closed.
My use case: i have an interceptor for tracing. It looks smth like this for unary:
but for stream iterceptor i can't do this, because intererceptor returns
Client
.So my proposal:
add CallOption that sets callback on stream close event:
So i would like to listen your thoughts about it.
The text was updated successfully, but these errors were encountered: