Comments (3)
What does "is busy" semantically mean here? If you want to check if the server just doesn't create the stream, you can use the timeout in the context, and it will return an error. Once a stream is created, your application handler can use it to signal back to the client based off properties about the server whether it is busy or not.
from grpc-go.
I did more testing and figured out that I needed to read from the stream on the client side to get the error. I was expecting to get the error on stream creation, which I suppose was naive.
Here is the server code:
grpc::Status TestV1ServiceImpl::run_session(::grpc::ServerContext *context,
::grpc::ServerReader<::test::v1::Request> *stream,
::google::protobuf::Empty *) {
{
auto cpu = utils::get_cpu_usage();
if (cpu > 0) {
printf("1111CPU usage %f exeeds 80\n", cpu);
return grpc::Status(grpc::StatusCode::RESOURCE_EXHAUSTED, "CPU resource exhausted");
}
}
proto::Request req;
while(true) {
auto res = stream->Read(&req);
if (!res) {
printf("Cancel connection. Read error\f");
return grpc::Status::CANCELLED;
} else {
printf("RECEIVED!\n");
}
}
}
And here is my client:
func main() {
conn, err := createConnection()
if err != nil {
fmt.Println("1: ", err)
panic(err)
}
ctx, _ := context.WithCancel(context.Background())
c := test.NewTestClient(conn)
stream, err := c.RunSession(ctx)
if err != nil {
fmt.Println("2: ", err)
panic(err)
}
m := new(emptypb.Empty)
for err == nil {
if err := stream.RecvMsg(m); err != nil {
fmt.Println("4: ", err)
panic(err)
}
}
fmt.Println("####EXITING####")
fmt.Println("5: ", err)
return
}
from grpc-go.
Great. Hope that solves your issue :)
from grpc-go.
Related Issues (20)
- use the google.golang.org/protobuf module instead HOT 2
- stats: peer is not populated for all HandleRPC client callbacks HOT 7
- Wait for ready with "readiness timeout" HOT 16
- How to catch the panic of sendResponse? HOT 5
- Response is not compressed when grpc-accept-encoding header contains spaces between values
- On AWS ALB a gRPC stream CloseSend() without a prior Send() is not received by server HOT 1
- Add new function to grpc ClientConn HOT 2
- Reuse compression buffer
- gRPC client reports the wrong status code if server response contains an unsupported encoding HOT 1
- Client waits with DNS query when no channel's available HOT 6
- Profile Guided Optimization results in high memory usage HOT 6
- Make server workers channel buffered? HOT 11
- xdsresolver uses ldsResourceName instead of using data plane authority HOT 2
- Question: PING frame HOT 7
- Call grpc.Invoke with nil "opts ...CallOption" throw a "invalid memory address or nil pointer dereference" and panics HOT 3
- Does gRPC-go URL encode `/`'s from xDS dial target HOT 1
- Stabilize `UseCompressor` and `SetSendCompressor` HOT 1
- subChannel triggerDelete lead to dead loop HOT 5
- xds: ADS stream failure triggers wildcard subscriptions on new stream HOT 11
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.