Giter Club home page Giter Club logo

Comments (3)

iamqizhao avatar iamqizhao commented on June 24, 2024

looking..

On Fri, May 8, 2015 at 7:45 AM, Russ Amos [email protected] wrote:

I have a stream defined that will send messages perpetually to the client,
until the client is no longer interested. Since there is no "stream.Close"
on the client side (only stream.CloseSend), I assume using
context.WithCancel on the client side is the correct way to do this.
However, it seems like cancelation is not being propagated to the server:
The server continues calling Send (with no errors) long after the client
stops caring, and eventually the Send blocks entirely and the server's
goroutine hangs. I think the goroutines are unblocked and exit if the
connection is closed, but I didn't test that thoroughly.

Unary RPCs seem to honor context cancelation.

Is there some other way for the client to indicate it is no longer
interested in the stream?


Reply to this email directly or view it on GitHub
#188.

from grpc-go.

iamqizhao avatar iamqizhao commented on June 24, 2024

ok, the right pattern to cancel a stream in your use case is as follows:

for {
  reply, err := stream.Recv()
  if err != nil {
    ...
  }
  if A {
    // not caring from now
    ctx.Cancel()
-  // YOU NEED TO KEEP READING UNTIL YOU GET CANCELED ERROR.*
  for {
    // stream.Recv() will make sure to cancel server side context if
  necessary.
    if _, err := stream.Recv(); err != nil {
      break
    }
  }
  }
  }

This design is intended because other alternatives either increases a fair
amount of overhead (a lot of more goroutine spawned by grpc) or introduces
much long latency to detect a cancellation. I should add this into the
document anyways.

Let me know if your issue gets addressed by this. Thank you for reporting.

On Fri, May 8, 2015 at 10:07 AM, Qi Zhao [email protected] wrote:

looking..

On Fri, May 8, 2015 at 7:45 AM, Russ Amos [email protected]
wrote:

I have a stream defined that will send messages perpetually to the
client, until the client is no longer interested. Since there is no
"stream.Close" on the client side (only stream.CloseSend), I assume using
context.WithCancel on the client side is the correct way to do this.
However, it seems like cancelation is not being propagated to the server:
The server continues calling Send (with no errors) long after the client
stops caring, and eventually the Send blocks entirely and the server's
goroutine hangs. I think the goroutines are unblocked and exit if the
connection is closed, but I didn't test that thoroughly.

Unary RPCs seem to honor context cancelation.

Is there some other way for the client to indicate it is no longer
interested in the stream?


Reply to this email directly or view it on GitHub
#188.

from grpc-go.

iamqizhao avatar iamqizhao commented on June 24, 2024

fixed by #189

from grpc-go.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.