-
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
New CallOption: grpc.ManualCancel #1923
Comments
I just recently ran into this- I'm curious if any code today would break if CloseSend actually "Closed". I've only seen CloseSend in defer statements in all example code, so maybe having CloseSend cause this goroutine to exit would be safe? |
@cstockton Are you thinking of |
Can you point me to the example you are talking about here? Calling |
@dfawley That is exactly what I was thinking, because CloseSend is on "Recv" only API's and it was also the only "Close" related function I could find. I posted my closing thoughts #2015 there. What it boils down to is as a client I want to be certain of one thing when I exit my call frame: request resources are released. I guess that just isn't possible without receiving all items, which I feel is unacceptable but I don't expect everyone will agree. |
We fork a goroutine for every stream here:
grpc-go/stream.go
Lines 297 to 304 in ec9275b
The main purpose of this goroutine is to monitor the user's context in order to abort the RPC when they cancel it. This introduces some moderate overhead on the cost of an RPC (~1-2%). To avoid this, we could instead add a
Cancel()
toclientStream
that users are able to call synchronously when they wish to cancel the stream (we may be doing this anyway). With this in place, if the user agrees to use it instead of the context for unscheduled cancellations (i.e. besides deadlines), we no longer need to fork this goroutine. There are some other prerequisites for this work. To list them all:clientStream.Cancel()
(New API: grpc.CancelClientStream(ClientStream) #1933)ClientConn
is closed. E.g. haveClientConn.Close()
synchronously cancel all active streams, or use callbacks from the transport when thenet.Conn
is closed.WaitUntil
on async.Cond
(sync: Cond WaitFor and/or WaitUntil method(s) golang/go#24429), something else will have to be used (e.g. atime.Timer
, a channel, and blocking on aselect
). [EDIT: or use async.Cond
and dotime.AfterFunc(nextTime, cond.Broadcast)
; stopping that timer if awoken before it fires.](It's possible 3 has similar overhead to forking a goroutine, in which case this would not be worth pursuing, so we would have to measure performance before starting on this.)
The text was updated successfully, but these errors were encountered: