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

@@ -14,6 +14,9 @@ pub enum Error {
ConnectionFailed(String),
/// Too many redirects. Synthetic error `500`.
TooManyRedirects,
/// We fail to read the status line. This happens for pooled connections when
/// TLS fails and we don't notice until trying to read.
BadStatusRead,
/// A status line we don't understand `HTTP/1.1 200 OK`. Synthetic error `500`.
BadStatus,
/// A header line that couldn't be parsed. Synthetic error `500`.
@@ -23,6 +26,15 @@ pub enum Error {
}
impl Error {
// If the error is bad status read, which might happen if a TLS connections is
// closed and we only discover it when trying to read the status line from it.
pub(crate) fn is_bad_status_read(&self) -> bool {
match self {
Error::BadStatusRead => true,
_ => false,
}
}
/// For synthetic responses, this is the error code.
pub fn status(&self) -> u16 {
match self {
@@ -31,6 +43,7 @@ impl Error {
Error::DnsFailed(_) => 400,
Error::ConnectionFailed(_) => 500,
Error::TooManyRedirects => 500,
Error::BadStatusRead => 500,
Error::BadStatus => 500,
Error::BadHeader => 500,
Error::Io(_) => 500,
@@ -45,6 +58,7 @@ impl Error {
Error::DnsFailed(_) => "Dns Failed",
Error::ConnectionFailed(_) => "Connection Failed",
Error::TooManyRedirects => "Too Many Redirects",
Error::BadStatusRead => "Failed to read status line",
Error::BadStatus => "Bad Status",
Error::BadHeader => "Bad Header",
Error::Io(_) => "Network Error",
@@ -59,6 +73,7 @@ impl Error {
Error::DnsFailed(err) => format!("Dns Failed: {}", err),
Error::ConnectionFailed(err) => format!("Connection Failed: {}", err),
Error::TooManyRedirects => "Too Many Redirects".to_string(),
Error::BadStatusRead => "Failed to read status line".to_string(),
Error::BadStatus => "Bad Status".to_string(),
Error::BadHeader => "Bad Header".to_string(),
Error::Io(ioe) => format!("Network Error: {}", ioe),