✨ feat(config): config option to timeout idle connections within the reqwest pool (#551)
This commit is contained in:
parent
bb50e8bb25
commit
b1df4f1154
3 changed files with 7 additions and 0 deletions
|
@ -44,6 +44,8 @@ pub struct Config {
|
|||
pub safe_search: u8,
|
||||
/// It stores the TCP connection keepalive duration in seconds.
|
||||
pub tcp_connection_keepalive: u8,
|
||||
/// It stores the pool idle connection timeout in seconds.
|
||||
pub pool_idle_connection_timeout: u8,
|
||||
}
|
||||
|
||||
impl Config {
|
||||
|
@ -134,6 +136,7 @@ impl Config {
|
|||
.get::<_, HashMap<String, bool>>("upstream_search_engines")?,
|
||||
request_timeout: globals.get::<_, u8>("request_timeout")?,
|
||||
tcp_connection_keepalive: globals.get::<_, u8>("tcp_connection_keepalive")?,
|
||||
pool_idle_connection_timeout: globals.get::<_, u8>("pool_idle_connection_timeout")?,
|
||||
threads,
|
||||
rate_limiter: RateLimiter {
|
||||
number_of_requests: rate_limiter["number_of_requests"],
|
||||
|
|
|
@ -78,6 +78,9 @@ pub async fn aggregate(
|
|||
let client = CLIENT.get_or_init(|| {
|
||||
ClientBuilder::new()
|
||||
.timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
||||
.pool_idle_timeout(Duration::from_secs(
|
||||
config.pool_idle_connection_timeout as u64,
|
||||
))
|
||||
.tcp_keepalive(Duration::from_secs(config.tcp_connection_keepalive as u64))
|
||||
.connect_timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
|
||||
.https_only(true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue