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)
- grpc.NewClient with namedpipe on Windows throws resolverError HOT 2
- User agent becomes grpc-go/1.64. on server side of grpc gateway HOT 3
- xds: move functionality from `xds/internal` to `internal/xds`
- stubserver: add support to optionally pass in a `grpc.Server` or `xds.GRPCServer` HOT 2
- Github Action: Codecov action is broken and is failing silently HOT 1
- Upgrade to using math/rand/v2 to get perf enhancements HOT 2
- xds: tests shouldn't rely on the presence of an entry in the `authorities` field of the bootstrap configuration with an empty key
- Experimental API related to metadata HOT 4
- Linter rule for using context.Background() without a timeout in tests HOT 4
- gRPC is incompatible with tls.Listener HOT 2
- Closing connection takes up to 15 minutes. HOT 4
- Feature Request: expose handleRawConn or add ServeConn HOT 19
- Flaky test: TimerAndWatchStateOnErrorCallback
- xds: bootstrap config is not emitted to logs in a human readable way
- Strongly-type request inside a Stream Server Interceptor HOT 1
- Proxy connection buffer necessary?
- Why does grpc.NewClient silently ignore DialOptions? HOT 2
- Make transport.SetConnection public? HOT 4
- what's the default max data size
- If a priority contains multiple localities with pick_first, load is reported incorrectly HOT 1
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.