Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add timeout for detect_region operation to prevent hanging request #16709

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/meta/app/src/storage/storage_params.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,15 @@
use std::fmt::Debug;
use std::fmt::Display;
use std::fmt::Formatter;
use std::time::Duration;

use databend_common_base::base::tokio::time::timeout;
use databend_common_exception::ErrorCode;
use databend_common_exception::Result;
use serde::Deserialize;
use serde::Serialize;

const DEFAULT_DETECT_REGION_TIMEOUT_SEC: u64 = 10;
/// Storage params which contains the detailed storage info.
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
#[serde(tag = "type")]
Expand Down Expand Up @@ -132,9 +136,16 @@ impl StorageParams {
format!("https://{}", endpoint)
};

s3.region = opendal::services::S3::detect_region(&endpoint, &s3.bucket)
.await
.unwrap_or_default();
s3.region = timeout(
Duration::from_secs(DEFAULT_DETECT_REGION_TIMEOUT_SEC),
opendal::services::S3::detect_region(&endpoint, &s3.bucket),
)
.await
.map_err(|e| {
ErrorCode::StorageOther(format!("detect region timeout, time used {}", e))
})?
.unwrap_or_default();

StorageParams::S3(s3)
}
v => v,
Expand Down
Loading