Skip to content

Long live grpc stream in bidirectional streaming #2228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
dbelozerovx1 opened this issue Mar 21, 2025 · 0 comments
Open

Long live grpc stream in bidirectional streaming #2228

dbelozerovx1 opened this issue Mar 21, 2025 · 0 comments

Comments

@dbelozerovx1
Copy link

dbelozerovx1 commented Mar 21, 2025

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::<SomeData>::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)
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant