-
Notifications
You must be signed in to change notification settings - Fork 49
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
fix timing issue of streaming #220
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #220 +/- ##
==========================================
+ Coverage 24.97% 25.22% +0.25%
==========================================
Files 16 16
Lines 2651 2704 +53
==========================================
+ Hits 662 682 +20
- Misses 1989 2022 +33 ☔ View full report in Codecov by Sentry. |
looks like ci is failing with #219 |
the stream request and data is handle asynchronously, if the data is handled when stream is not created yet, the data will be discarded and an error occur. Signed-off-by: Abel <[email protected]>
code is rebased, please take a look. and CI error of Coverage seems a network error? @jsturtevant |
@@ -381,12 +381,14 @@ impl ReaderDelegate for ServerReader { | |||
async fn handle_msg(&self, msg: GenMessage) { | |||
let handler_shutdown_waiter = self.handler_shutdown.subscribe(); | |||
let context = self.context(); | |||
let (wait_tx, wait_rx) = tokio::sync::oneshot::channel::<()>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More make sence to use tokio::sync::Barrier?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Barrier is for blocking a number of tasks, but here we just need to block the current task, it seems the oneshot channel is a simpler choice, I think.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we can use tokio::sync::Notify, but as it do not implement Drop so that we have to call notify_one()
in a lot of places otherwise the handle_msg
method of ServerReader
will be blocked if we miss calling notify_one()
in any code branches, hence I think it is easy to introduce bugs.
I think the oneshot::channel is a better choice because whenever it is droped, the wait of it will be unblocked. so we don't have to call drop everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oneshot is ok in my opinion
cherry-pick containerd#220 containerd#222 containerd#220 from containerd/ttrpc-rust
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abel-von Good catch, thanks
The stream request and data is handle asynchronously, if the data is handled when stream is not created yet, the data will be discarded and an error occur.
we should wait until the stream is created and then the subsequent message can be handled.