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

use executor-agnostic timers #298

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tarpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ travis-ci = { repository = "google/tarpc" }
[dependencies]
fnv = "1.0"
futures = "0.3"
futures-timer = "3.0"

Choose a reason for hiding this comment

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

We've seen some issues come from this crate in the past just FYI. I would advise against using it.

humantime = "1.0"
log = "0.4"
pin-project = "0.4"
Expand Down
12 changes: 8 additions & 4 deletions tarpc/src/rpc/client/channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use futures::{
stream::Fuse,
task::*,
};
use futures_timer::Delay;
use log::{debug, info, trace};
use pin_project::{pin_project, pinned_drop, project};
use std::{
Expand Down Expand Up @@ -78,7 +79,7 @@ impl<'a, Req, Resp> Future for Send<'a, Req, Resp> {
#[must_use = "futures do nothing unless polled"]
pub struct Call<'a, Req, Resp> {
#[pin]
fut: tokio::time::Timeout<AndThenIdent<Send<'a, Req, Resp>, DispatchResponse<Resp>>>,
fut: future::Select<Pin<Box<AndThenIdent<Send<'a, Req, Resp>, DispatchResponse<Resp>>>>, Delay>,
}

impl<'a, Req, Resp> Future for Call<'a, Req, Resp> {
Expand All @@ -87,8 +88,8 @@ impl<'a, Req, Resp> Future for Call<'a, Req, Resp> {
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let resp = ready!(self.as_mut().project().fut.poll(cx));
Poll::Ready(match resp {
Ok(resp) => resp,
Err(tokio::time::Elapsed { .. }) => Err(io::Error::new(
future::Either::Left((resp, _)) => resp,
future::Either::Right(_) => Err(io::Error::new(
io::ErrorKind::TimedOut,
"Client dropped expired request.".to_string(),
)),
Expand Down Expand Up @@ -137,7 +138,10 @@ impl<Req, Resp> Channel<Req, Resp> {
);

Call {
fut: tokio::time::timeout(timeout, AndThenIdent::new(self.send(ctx, request))),
fut: future::select(
Box::pin(AndThenIdent::new(self.send(ctx, request))),
Delay::new(timeout),
),
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tarpc/src/rpc/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ use futures::{
stream::Fuse,
task::*,
};
use futures_timer::Delay;
use humantime::format_rfc3339;
use log::{debug, trace};
use pin_project::pin_project;
use std::{fmt, hash::Hash, io, marker::PhantomData, pin::Pin, time::SystemTime};
use tokio::time::Timeout;

mod filter;
#[cfg(test)]
Expand Down Expand Up @@ -487,7 +487,7 @@ where
request_id,
ctx,
deadline,
f: tokio::time::timeout(timeout, response),
f: future::select(Box::pin(response), Delay::new(timeout)),
response: None,
response_tx: self.as_mut().project().responses_tx.clone(),
};
Expand Down Expand Up @@ -526,7 +526,7 @@ struct Resp<F, R> {
ctx: context::Context,
deadline: SystemTime,
#[pin]
f: Timeout<F>,
f: future::Select<Pin<Box<F>>, Delay>,
response: Option<Response<R>>,
#[pin]
response_tx: mpsc::Sender<(context::Context, Response<R>)>,
Expand Down Expand Up @@ -554,8 +554,8 @@ where
*self.as_mut().project().response = Some(Response {
request_id: self.request_id,
message: match result {
Ok(message) => Ok(message),
Err(tokio::time::Elapsed { .. }) => {
future::Either::Left((message, _)) => Ok(message),
future::Either::Right(_) => {
debug!(
"[{}] Response did not complete before deadline of {}s.",
self.ctx.trace_id(),
Expand Down