Skip to content
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

how to manually fail a client streaming? #1758

Open
glorv opened this issue Jun 26, 2024 · 0 comments
Open

how to manually fail a client streaming? #1758

glorv opened this issue Jun 26, 2024 · 0 comments

Comments

@glorv
Copy link

glorv commented Jun 26, 2024

Currently, client stream receives a request with type impl tonic::IntoStreamingRequest<Message=...>, it seems not expose a interface to manually fail this streaming. A real world user case is to use client streaming to send a file, each message represent a chunk of this file. It is possible that the source of file may meet error, e.g, read from a disk file meet IO errors, thus we may want to manually terminate the streaming with a fail status so the server side can know that this is not s successful call.

I saw the internal pat of the client streaming will also transfer this stream to Stream<Item=<Result<Message, tonic::Status>>> at:

pub(crate) fn encode_client<T, U>(
encoder: T,
source: U,
compression_encoding: Option<CompressionEncoding>,
max_message_size: Option<usize>,
) -> EncodeBody<impl Stream<Item = Result<Bytes, Status>>>
where
T: Encoder<Error = Status>,
U: Stream<Item = T::Item>,
{
let stream = EncodedBytes::new(
encoder,
source.fuse().map(Ok),
compression_encoding,
SingleMessageCompressionOverride::default(),
max_message_size,
);

thus, it is better to expose the Result to the input type? Why not directly the request type as impl tonic::IntoStreamingRequest<Message=Result<ReqType, tonic::Status>>?

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