Retry some pooled connections failing when server closes. Close #10

This is not a perfect solution. It works as long as we are not sending
any body bytes. We discover the error first when attempting to read
the response status line. That means we discover the error after
sending body bytes. To be able to re-send the body, we would need to
introduce a buffer to be able to replay the body on the next
request. We don't currently do that.
This commit is contained in:
Martin Algesten
2019-10-20 21:32:19 +02:00
parent 1264213ca6
commit 753d61b454
5 changed files with 64 additions and 8 deletions

View File

@@ -51,3 +51,29 @@ fn agent_cookies() {
agent.get("test://host/agent_cookies").call();
}
#[test]
fn connection_reuse() {
use std::io::Read;
use std::time::Duration;
let agent = Agent::default().build();
let resp = agent.get("https://fau.xxx/").call();
// use up the connection so it gets returned to the pool
assert_eq!(resp.status(), 200);
resp.into_reader().read_to_end(&mut vec![]).unwrap();
// wait for the server to close the connection. fau.xxx has a
// 2 second connection keep-alive. then it closes.
std::thread::sleep(Duration::from_secs(3));
// try and make a new request on the pool. this fails
// when we discover that the TLS connection is dead
// first when attempting to read from it.
let resp = agent.get("https://fau.xxx/").call();
if let Some(err) = resp.synthetic_error() {
panic!("Pooled connection failed! {:?}", err);
}
assert_eq!(resp.status(), 200);
}