Kekma commited on
Commit
b1df4f1
1 Parent(s): bb50e8b

:sparkles: feat(config): config option to timeout idle connections within the reqwest pool (#551)

Browse files
src/config/parser.rs CHANGED
@@ -44,6 +44,8 @@ pub struct Config {
44
  pub safe_search: u8,
45
  /// It stores the TCP connection keepalive duration in seconds.
46
  pub tcp_connection_keepalive: u8,
 
 
47
  }
48
 
49
  impl Config {
@@ -134,6 +136,7 @@ impl Config {
134
  .get::<_, HashMap<String, bool>>("upstream_search_engines")?,
135
  request_timeout: globals.get::<_, u8>("request_timeout")?,
136
  tcp_connection_keepalive: globals.get::<_, u8>("tcp_connection_keepalive")?,
 
137
  threads,
138
  rate_limiter: RateLimiter {
139
  number_of_requests: rate_limiter["number_of_requests"],
 
44
  pub safe_search: u8,
45
  /// It stores the TCP connection keepalive duration in seconds.
46
  pub tcp_connection_keepalive: u8,
47
+ /// It stores the pool idle connection timeout in seconds.
48
+ pub pool_idle_connection_timeout: u8,
49
  }
50
 
51
  impl Config {
 
136
  .get::<_, HashMap<String, bool>>("upstream_search_engines")?,
137
  request_timeout: globals.get::<_, u8>("request_timeout")?,
138
  tcp_connection_keepalive: globals.get::<_, u8>("tcp_connection_keepalive")?,
139
+ pool_idle_connection_timeout: globals.get::<_, u8>("pool_idle_connection_timeout")?,
140
  threads,
141
  rate_limiter: RateLimiter {
142
  number_of_requests: rate_limiter["number_of_requests"],
src/results/aggregator.rs CHANGED
@@ -78,6 +78,9 @@ pub async fn aggregate(
78
  let client = CLIENT.get_or_init(|| {
79
  ClientBuilder::new()
80
  .timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
 
 
 
81
  .tcp_keepalive(Duration::from_secs(config.tcp_connection_keepalive as u64))
82
  .connect_timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
83
  .https_only(true)
 
78
  let client = CLIENT.get_or_init(|| {
79
  ClientBuilder::new()
80
  .timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
81
+ .pool_idle_timeout(Duration::from_secs(
82
+ config.pool_idle_connection_timeout as u64,
83
+ ))
84
  .tcp_keepalive(Duration::from_secs(config.tcp_connection_keepalive as u64))
85
  .connect_timeout(Duration::from_secs(config.request_timeout as u64)) // Add timeout to request to avoid DDOSing the server
86
  .https_only(true)
websurfx/config.lua CHANGED
@@ -11,6 +11,7 @@ production_use = false -- whether to use production mode or not (in other words
11
  -- There will be a random delay before sending the request to the search engines, this is to prevent DDoSing the upstream search engines from a large number of simultaneous requests.
12
  request_timeout = 30 -- timeout for the search requests sent to the upstream search engines to be fetched (value in seconds).
13
  tcp_connection_keepalive = 30 -- the amount of time the tcp connection should remain alive (or connected to the server). (value in seconds).
 
14
  rate_limiter = {
15
  number_of_requests = 20, -- The number of request that are allowed within a provided time limit.
16
  time_limit = 3, -- The time limit in which the quantity of requests that should be accepted.
 
11
  -- There will be a random delay before sending the request to the search engines, this is to prevent DDoSing the upstream search engines from a large number of simultaneous requests.
12
  request_timeout = 30 -- timeout for the search requests sent to the upstream search engines to be fetched (value in seconds).
13
  tcp_connection_keepalive = 30 -- the amount of time the tcp connection should remain alive (or connected to the server). (value in seconds).
14
+ pool_idle_connection_timeout = 30 -- timeout for the idle connections in the reqwest HTTP connection pool (value in seconds).
15
  rate_limiter = {
16
  number_of_requests = 20, -- The number of request that are allowed within a provided time limit.
17
  time_limit = 3, -- The time limit in which the quantity of requests that should be accepted.