Skip to content

Commit

Permalink
Merge pull request #229 from dandi/gh-62
Browse files Browse the repository at this point in the history
Timeout outgoing non-S3 requests after 10 seconds
  • Loading branch information
jwodder authored Jan 23, 2025
2 parents 0afe450 + 207b52b commit 9a7abc3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ In Development
- Rate limit incoming requests
- Handling of incoming requests now times out after 25 seconds
- Increased MSRV to 1.81
- Outgoing requests to servers other than S3 now time out after 10 seconds

v0.5.0 (2024-11-18)
-------------------
Expand Down
5 changes: 5 additions & 0 deletions src/dav/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ pub(crate) enum ErrorClass {
/// error or invalid response
BadGateway,

/// The error was ultimately caused by a request to an upstream server
/// timing out
GatewayTimeout,

/// The error was ultimately caused by something going wrong in `dandidav`
Internal,
}
Expand All @@ -446,6 +450,7 @@ impl ErrorClass {
match self {
ErrorClass::NotFound => StatusCode::NOT_FOUND,
ErrorClass::BadGateway => StatusCode::BAD_GATEWAY,
ErrorClass::GatewayTimeout => StatusCode::GATEWAY_TIMEOUT,
ErrorClass::Internal => StatusCode::INTERNAL_SERVER_ERROR,
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/httputil.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ impl Client {
let client = reqwest_middleware::ClientBuilder::new(
reqwest::ClientBuilder::new()
.user_agent(USER_AGENT)
.timeout(std::time::Duration::from_secs(10))
.build()?,
)
.with(SimpleReqwestLogger)
Expand Down Expand Up @@ -184,6 +185,10 @@ impl HttpError {
pub(crate) fn class(&self) -> ErrorClass {
match self {
HttpError::NotFound { .. } => ErrorClass::NotFound,
HttpError::Send { source, .. } if source.is_timeout() => ErrorClass::GatewayTimeout,
HttpError::Deserialize { source, .. } if source.is_timeout() => {
ErrorClass::GatewayTimeout
}
_ => ErrorClass::BadGateway,
}
}
Expand Down

0 comments on commit 9a7abc3

Please sign in to comment.