grpc / grpc/grpc-rust

Long live grpc stream in bidirectional streaming

Open
#2,228 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
12.5k
Forks
1.3k
Avg merge
4d 7h
Merged PRs (30d)
24

Description

We've discovered a problem using tonic lib for our rust client, trying to send streaming messages, seems like tonic recreate the stream on every message, so more featured server which logic is concreted to listen same stream(for perfomance, resources issues, etc), receiving complete stream signals and new one being created

`
fn send() {
let data = SomeData {
...data
};

let response = match self.client.put_data(tokio_stream::iter(vec![data])).await {
Ok(res) => res,
Err(st) => ...fail processing,
};
}
`

i am suspicious that put_data(tokio_stream::iter(vec![data]) is recreating stream on each send() function call

example in repo have the same behavior https://github.com/hyperium/tonic/blob/master/examples/src/streaming/client.rs#L35

is there anyway to avoid such behavior? maybe different approach with example?

i saw the way with channels like so

`
let (tx, rx) = mpsc::unbounded_channel();
let stream = UnboundedReceiverStream::::new(rx);
`
and then pass the stream directly to client.put_data like so

`
let response = match self.client.put_data(self.stream)
`

but here's the same problem, stream will be recreated each time and if i want to store that stream in the struct i cannot move it then later, so i cannot just spawn task with infinite loop, cause i need to process data from response streams, is there any way to solve this issue?

what i want basically something like https://grpc.io/docs/languages/go/basics/#client-side-streaming-rpc-1

where i can initiate stream like so stream, err := client.RecordRoute(context.Background())

and then use it across entire app

if err := stream.Send(point); err != nil {
log.Fatalf("%v.Send(%v) = %v", stream, point, err)
}

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.