Thanks for the quick reply. Should of specified that the code in the
original post is a snippet, there's receiving logic underneath it.
Some more details surrounding this. In this case I have a callback function
on the server (written in python) that needs to be executed to free
resources, so closing the sending portion does not seems to trigger that.
Also the client in this case dictates all connections. The server simply
pours a stream of data to the client until the client no longer needs that
particular data. So to be more specific with my question how would I fully
close the stream from the client's side?
On Monday, February 6, 2017 at 9:50:04 AM UTC-6, Josh Humphries wrote:
>
> Perhaps more helpful: in your code example, you would then consume the
> responses by calling Recv() on the stream until it returns an error (io.EOF
> on successful end of stream or some other error if the call fails). Even if
> you are not expecting any response data from the server, you want to call
> Recv() in order to learn the ultimate disposition of the call (did it
> result in an error in the server or was it processed successfully?).
>
> log.Println("stream starting")
> streamCtx, cancel := context.WithCancel(ctx)
> defer cancel()
> stream, err := grpcStream(streamCtx, otherArgs)
> if err != nil {
> errCh <- err
> return
> }
> defer stream.CloseSend()
> defer log.Println("closing stream")
> for {
> msg, err := stream.Recv()
> if err == io.EOF {
> break
> }
> if err != nil {
> errCh <- err
> return
> }
> }
>
>
> ----
>
> Josh Humphries
>
> FullStory <https://www.fullstory.com/> | Atlanta, GA
>
> Software Engineer
>
> [email protected] <javascript:>
>
> On Mon, Feb 6, 2017 at 10:36 AM, Josh Humphries <[email protected]
> <javascript:>> wrote:
>
>> On the client, the CloseSend method is "half-closing" the stream. So it
>> closes the request/upload half of the stream. The stream remains open until
>> the server closes the other half: the response/download part of the stream.
>> Cancelling the stream also closes it (as would the channel being
>> disconnected or the call timing out).
>>
>>
>>
>> ----
>>
>> Josh Humphries
>>
>> FullStory <https://www.fullstory.com/> | Atlanta, GA
>>
>> Software Engineer
>>
>> [email protected] <javascript:>
>>
>> On Mon, Feb 6, 2017 at 10:29 AM, Michael Bond <[email protected]
>> <javascript:>> wrote:
>>
>>> Hey, trying to make sure I'm doing this correctly.
>>>
>>> Right now I'm having issues with closing streams started with a context
>>> that is passed around and exists for quite awhile.
>>>
>>> In this example "ctx" is passed around to many go routines, I want to
>>> keep "ctx" around but passing it to "grpcStream" seems to keep the stream
>>> from actually closing. What I did below fixed the issue but I wanted to
>>> know if it is needed to pass a child context and cancel it for the stream
>>> to actually close. Is CloseSend() not sufficient if the context is still
>>> alive?
>>>
>>> log.Println("stream starting")
>>> streamCtx, cancel := context.WithCancel(ctx)
>>> defer cancel()
>>> stream, err := grpcStream(streamCtx, otherArgs)
>>> if err != nil {
>>> errCh <- err
>>> return
>>> }
>>> defer stream.CloseSend()
>>> defer log.Println("closing stream")
>>>
>>> Thanks!
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "grpc.io" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to [email protected] <javascript:>.
>>> To post to this group, send email to [email protected]
>>> <javascript:>.
>>> Visit this group at https://groups.google.com/group/grpc-io.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/grpc-io/85470940-69e3-4f4c-aed2-31a3242841a3%40googlegroups.com
>>>
>>> <https://groups.google.com/d/msgid/grpc-io/85470940-69e3-4f4c-aed2-31a3242841a3%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>
--
You received this message because you are subscribed to the Google Groups
"grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit
https://groups.google.com/d/msgid/grpc-io/3fbe82ba-8812-4095-8cf3-9784bdb03789%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.