Skip to content

Commit ee61ea9

Browse files
committed
feat(client): Client will retry requests on fresh connections
If a request sees an error on a pooled connection before ever writing any bytes, it will now retry with a new connection. This can be configured with `Config::retry_canceled_requests(bool)`.
1 parent 0ea3bcf commit ee61ea9

File tree

6 files changed

+224
-114
lines changed

6 files changed

+224
-114
lines changed

src/client/dispatch.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use futures::sync::{mpsc, oneshot};
44
use common::Never;
55
use super::cancel::{Cancel, Canceled};
66

7-
pub type Callback<U> = oneshot::Sender<::Result<U>>;
8-
pub type Promise<U> = oneshot::Receiver<::Result<U>>;
7+
pub type Callback<T, U> = oneshot::Sender<Result<U, (::Error, Option<T>)>>;
8+
pub type Promise<T, U> = oneshot::Receiver<Result<U, (::Error, Option<T>)>>;
99

1010
pub fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
1111
let (tx, rx) = mpsc::unbounded();
@@ -23,7 +23,7 @@ pub fn channel<T, U>() -> (Sender<T, U>, Receiver<T, U>) {
2323

2424
pub struct Sender<T, U> {
2525
cancel: Cancel,
26-
inner: mpsc::UnboundedSender<(T, Callback<U>)>,
26+
inner: mpsc::UnboundedSender<(T, Callback<T, U>)>,
2727
}
2828

2929
impl<T, U> Sender<T, U> {
@@ -35,7 +35,7 @@ impl<T, U> Sender<T, U> {
3535
self.cancel.cancel();
3636
}
3737

38-
pub fn send(&self, val: T) -> Result<Promise<U>, T> {
38+
pub fn send(&self, val: T) -> Result<Promise<T, U>, T> {
3939
let (tx, rx) = oneshot::channel();
4040
self.inner.unbounded_send((val, tx))
4141
.map(move |_| rx)
@@ -54,11 +54,11 @@ impl<T, U> Clone for Sender<T, U> {
5454

5555
pub struct Receiver<T, U> {
5656
canceled: Canceled,
57-
inner: mpsc::UnboundedReceiver<(T, Callback<U>)>,
57+
inner: mpsc::UnboundedReceiver<(T, Callback<T, U>)>,
5858
}
5959

6060
impl<T, U> Stream for Receiver<T, U> {
61-
type Item = (T, Callback<U>);
61+
type Item = (T, Callback<T, U>);
6262
type Error = Never;
6363

6464
fn poll(&mut self) -> Poll<Option<Self::Item>, Self::Error> {
@@ -83,9 +83,9 @@ impl<T, U> Drop for Receiver<T, U> {
8383
// - Ready(None): the end. we want to stop looping
8484
// - NotReady: unreachable
8585
// - Err: unreachable
86-
while let Ok(Async::Ready(Some((_val, cb)))) = self.inner.poll() {
86+
while let Ok(Async::Ready(Some((val, cb)))) = self.inner.poll() {
8787
// maybe in future, we pass the value along with the error?
88-
let _ = cb.send(Err(::Error::new_canceled(None)));
88+
let _ = cb.send(Err((::Error::new_canceled(None), Some(val))));
8989
}
9090
}
9191

0 commit comments

Comments
 (0)