Skip to content

Commit

Permalink
chore: add timeout for detect_region operation to prevent hanging r…
Browse files Browse the repository at this point in the history
…equest (#16709)

chore: add timeout for `detect_region` operation to prevent hanging requests
  • Loading branch information
dantengsky authored Oct 28, 2024
1 parent 82814bf commit a2b8adc
Showing 1 changed file with 14 additions and 3 deletions.
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

0 comments on commit a2b8adc

Please sign in to comment.