aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrew Hauck <[email protected]>2024-03-07 22:08:34 -0800
committerEdward Wang <[email protected]>2024-03-15 14:37:56 -0700
commit3e09114c4d1fd5ccae8ef0526c72d232ef1fdc58 (patch)
treeda8c7cf8243b989eae78d17c07c3db497963468a
parentd2c8118ef4adff77b61f605a57146a7f3c09f100 (diff)
downloadpingora-3e09114c4d1fd5ccae8ef0526c72d232ef1fdc58.tar.gz
pingora-3e09114c4d1fd5ccae8ef0526c72d232ef1fdc58.zip
Treat OS read timeouts as ReadError rather than ReadTimeout when reading http/1.1 response headers
-rw-r--r--.bleep2
-rw-r--r--pingora-core/src/protocols/http/v1/client.rs40
2 files changed, 17 insertions, 25 deletions
diff --git a/.bleep b/.bleep
index 5c2290a..66c4bb2 100644
--- a/.bleep
+++ b/.bleep
@@ -1 +1 @@
-a8c217af0e62780f87c43d0ede0bebf31a545c17 \ No newline at end of file
+90d84b32f4528ede68b8351c896a101af788113d \ No newline at end of file
diff --git a/pingora-core/src/protocols/http/v1/client.rs b/pingora-core/src/protocols/http/v1/client.rs
index e28d2af..13e0482 100644
--- a/pingora-core/src/protocols/http/v1/client.rs
+++ b/pingora-core/src/protocols/http/v1/client.rs
@@ -185,10 +185,9 @@ impl HttpSession {
let read_fut = self.underlying_stream.read_buf(&mut buf);
let read_result = match self.read_timeout {
- Some(t) => match timeout(t, read_fut).await {
- Ok(res) => res,
- Err(_) => Err(std::io::Error::from(ErrorKind::TimedOut)),
- },
+ Some(t) => timeout(t, read_fut)
+ .await
+ .map_err(|_| Error::explain(ReadTimedout, "while reading response headers"))?,
None => read_fut.await,
};
let n = match read_result {
@@ -208,26 +207,19 @@ impl HttpSession {
}
},
Err(e) => {
- return match e.kind() {
- ErrorKind::TimedOut => {
- Error::e_explain(ReadTimedout, "while reading response headers")
- }
- _ => {
- let true_io_error = e.raw_os_error().is_some();
- let mut e = Error::because(
- ReadError,
- format!(
- "while reading response headers, bytes already read: {already_read}",
- ),
- e,
- );
- // Likely OSError, typical if a previously reused connection drops it
- if true_io_error {
- e.retry = RetryType::ReusedOnly;
- } // else: not safe to retry TLS error
- Err(e)
- }
- };
+ let true_io_error = e.raw_os_error().is_some();
+ let mut e = Error::because(
+ ReadError,
+ format!(
+ "while reading response headers, bytes already read: {already_read}",
+ ),
+ e,
+ );
+ // Likely OSError, typical if a previously reused connection drops it
+ if true_io_error {
+ e.retry = RetryType::ReusedOnly;
+ } // else: not safe to retry TLS error
+ return Err(e);
}
};
already_read += n;