refactor(client): only spawn pooled in executor if not ready when response recieved

This commit is contained in:
Sean McArthur
2018-03-13 18:46:52 -07:00
parent 26ec18a282
commit 91b9700862
3 changed files with 130 additions and 105 deletions

View File

@@ -243,20 +243,27 @@ where C: Connect,
} else {
ClientError::Normal(err)
}
})
.map(move |res| {
// when pooled is dropped, it will try to insert back into the
// pool. To delay that, spawn a future that completes once the
// sender is ready again.
//
// This *should* only be once the related `Connection` has polled
// for a new request to start.
//
// It won't be ready if there is a body to stream.
if let Ok(Async::NotReady) = pooled.tx.poll_ready() {
// If the executor doesn't have room, oh well. Things will likely
// be blowing up soon, but this specific task isn't required.
let _ = executor.execute(future::poll_fn(move || {
pooled.tx.poll_ready().map_err(|_| ())
}));
}
res
});
// when pooled is dropped, it will try to insert back into the
// pool. To delay that, spawn a future that completes once the
// sender is ready again.
//
// This *should* only be once the related `Connection` has polled
// for a new request to start.
//
// If the executor doesn't have room, oh well. Things will likely
// be blowing up soon, but this specific task isn't required.
let _ = executor.execute(future::poll_fn(move || {
pooled.tx.poll_ready().map_err(|_| ())
}));
fut
});

View File

@@ -1,10 +1,8 @@
extern crate pretty_env_logger;
use std::time::Duration;
use futures::Async;
use futures::future::poll_fn;
use tokio::reactor::{Core, Timeout};
use tokio::reactor::Core;
use mock::MockConnector;
use super::*;
@@ -70,11 +68,6 @@ fn conn_reset_after_write() {
Ok(Async::Ready(()))
});
core.run(res1.join(srv1)).expect("res1");
// run a tiny timeout just to spin the core, so that the pool
// can tell the socket is ready again
let timeout = Timeout::new(Duration::from_millis(50), &core.handle()).unwrap();
core.run(timeout).unwrap();
}
let res2 = client.get("http://mock.local/a".parse().unwrap());