Comments (3)
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.
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.
fixed by #189
from grpc-go.
Related Issues (20)
- Convert remaining uses of gracefulswitch to use `gracefulswitch.ParseConfig` and not `SwitchTo` HOT 2
- Update docs and examples and tests to use `NewClient` instead of `Dial` HOT 14
- How can the client automate the handling of the GOAWAY signal? HOT 5
- protoc-gen-go-grpc: empty const block causing `gofmt` failure
- failed to listen: listen tcp :50051: bind: address already in use exit status 1 HOT 3
- Add support for using zap.Object HOT 2
- protoc-gen-go-grpc: support proto edition HOT 3
- The API Gateway vision HOT 4
- Issue creating a ENUM with "name" field HOT 2
- metadata validation disallows UTF-8/ISO-8859-1 characters in headers HOT 6
- Possible regression when using NewClient instead of Dial HOT 1
- Is dynamic routing currently supported in grpc-go or how can i achieve itοΌ HOT 6
- Is it possible to split service implementaion? HOT 3
- Deprecation of `DialContext` and `Dial` is not mentioned in 1.63.0 release notes HOT 3
- bufnet not supported by NewClient() ? HOT 5
- Please release upgrade /cmd/protoc-gen-go-grpc /go.mod to security fixed protobuf v1.33.0 HOT 2
- Confusing for NewClient in 1.63 HOT 4
- Deprecate WithBlock and WithReturnConnectionError HOT 3
- gRPC casing looks really ugly [Serious] HOT 2
- resolver.Address's BalancerAttributes update will not reflect in Balancer HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from grpc-go.