Skip to content

Add example of detecting client drops in bidirectional streams on server side#931

Merged
LucioFranco merged 4 commits intohyperium:masterfrom
xoac:bidiractional-stream-example
Mar 3, 2022
Merged

Add example of detecting client drops in bidirectional streams on server side#931
LucioFranco merged 4 commits intohyperium:masterfrom
xoac:bidiractional-stream-example

Conversation

@xoac
Copy link
Copy Markdown
Contributor

@xoac xoac commented Feb 27, 2022

closes #781

I think that this example shows also a weakness of tonic. For example in async fn server_streaming_echo() function is impossible (or I do not know how) to get reason why output_stream wasn't able to send message to client.

Motivation

Provide example how to detect client disconnection on server side

Solution

Use tokio::spawn to separate await on input stream from output stream.

Copy link
Copy Markdown
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a good start! Left a few comments.

Comment thread examples/Cargo.toml Outdated
Comment thread examples/src/streaming/client.rs Outdated
}
}

async fn bidirectional_streaming_echo_throttle(client: &mut EchoClient<Channel>, dur: Duration) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not following why we want this example as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted to show difference between graceful stream end the one when client disconnected for example by broken connection or just crush. This 2 functions could be unified to one.

Here is the output from server part.

EchoServer::server_streaming_echo
	client connected from: Some([::1]:36750)
	client disconnected
EchoServer::Bidirectional_streaming_echo
	stream ended
EchoServer::Bidirectional_streaming_echo
	client disconnected: broken pipe
	stream ended

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other words the difference is on the server side. On the client side I just needed a function that sends request slowly enough that you can write what is printed. I added additional comments to clarify that.

Should I unify this to bidirectional_streaming_echo(client &mut EchoClient<Channel>, num_reqs: usize, throttle: Duration)?

Comment thread examples/src/streaming/server.rs
Comment thread examples/src/streaming/server.rs
@xoac xoac requested a review from LucioFranco March 2, 2022 00:16
Copy link
Copy Markdown
Member

@LucioFranco LucioFranco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@LucioFranco LucioFranco merged commit 01e5be5 into hyperium:master Mar 3, 2022
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

Successfully merging this pull request may close these issues.

Detect client drops in bidirectional streams

2 participants