no idle timeout or max lifetime

This commit is contained in:
Bryan Stitt 2022-09-19 22:41:53 +00:00
parent b2adc73b50
commit 8785cb6d2d
2 changed files with 9 additions and 11 deletions

View File

@ -68,9 +68,9 @@ where
// TODO: DO NOT UNWRAP HERE. figure out how to handle anyhow error being wrapped in an Arc // TODO: DO NOT UNWRAP HERE. figure out how to handle anyhow error being wrapped in an Arc
// TODO: i'm sure this could be a lot better. but race conditions make this hard to think through. brain needs sleep // TODO: i'm sure this could be a lot better. but race conditions make this hard to think through. brain needs sleep
let arc_key_count: Arc<AtomicU64> = { let local_key_count: Arc<AtomicU64> = {
// clone things outside of the `async move` // clone things outside of the `async move`
let arc_deferred_rate_limit_result = arc_deferred_rate_limit_result.clone(); let deferred_rate_limit_result = arc_deferred_rate_limit_result.clone();
let redis_key = redis_key.clone(); let redis_key = redis_key.clone();
let rrl = Arc::new(self.rrl.clone()); let rrl = Arc::new(self.rrl.clone());
@ -83,14 +83,14 @@ where
.await .await
{ {
Ok(RedisRateLimitResult::Allowed(count)) => { Ok(RedisRateLimitResult::Allowed(count)) => {
let _ = arc_deferred_rate_limit_result let _ = deferred_rate_limit_result
.lock() .lock()
.await .await
.insert(DeferredRateLimitResult::Allowed); .insert(DeferredRateLimitResult::Allowed);
count count
} }
Ok(RedisRateLimitResult::RetryAt(retry_at, count)) => { Ok(RedisRateLimitResult::RetryAt(retry_at, count)) => {
let _ = arc_deferred_rate_limit_result let _ = deferred_rate_limit_result
.lock() .lock()
.await .await
.insert(DeferredRateLimitResult::RetryAt(retry_at)); .insert(DeferredRateLimitResult::RetryAt(retry_at));
@ -100,7 +100,7 @@ where
panic!("RetryNever shouldn't happen") panic!("RetryNever shouldn't happen")
} }
Err(err) => { Err(err) => {
let _ = arc_deferred_rate_limit_result let _ = deferred_rate_limit_result
.lock() .lock()
.await .await
.insert(DeferredRateLimitResult::Allowed); .insert(DeferredRateLimitResult::Allowed);
@ -126,7 +126,7 @@ where
Ok(deferred_rate_limit_result) Ok(deferred_rate_limit_result)
} else { } else {
// we have a cached amount here // we have a cached amount here
let cached_key_count = arc_key_count.fetch_add(count, Ordering::Acquire); let cached_key_count = local_key_count.fetch_add(count, Ordering::Acquire);
// assuming no other parallel futures incremented this key, this is the count that redis has // assuming no other parallel futures incremented this key, this is the count that redis has
let expected_key_count = cached_key_count + count; let expected_key_count = cached_key_count + count;
@ -153,11 +153,11 @@ where
.await .await
{ {
Ok(RedisRateLimitResult::Allowed(count)) => { Ok(RedisRateLimitResult::Allowed(count)) => {
arc_key_count.store(count, Ordering::Release); local_key_count.store(count, Ordering::Release);
DeferredRateLimitResult::Allowed DeferredRateLimitResult::Allowed
} }
Ok(RedisRateLimitResult::RetryAt(retry_at, count)) => { Ok(RedisRateLimitResult::RetryAt(retry_at, count)) => {
arc_key_count.store(count, Ordering::Release); local_key_count.store(count, Ordering::Release);
DeferredRateLimitResult::RetryAt(retry_at) DeferredRateLimitResult::RetryAt(retry_at)
} }
Ok(RedisRateLimitResult::RetryNever) => { Ok(RedisRateLimitResult::RetryNever) => {

View File

@ -133,11 +133,9 @@ pub async fn get_migrated_db(
// TODO: load all these options from the config file. i think mysql default max is 100 // TODO: load all these options from the config file. i think mysql default max is 100
// TODO: sqlx logging only in debug. way too verbose for production // TODO: sqlx logging only in debug. way too verbose for production
db_opt db_opt
.connect_timeout(Duration::from_secs(30))
.min_connections(min_connections) .min_connections(min_connections)
.max_connections(max_connections) .max_connections(max_connections)
.connect_timeout(Duration::from_secs(8))
.idle_timeout(Duration::from_secs(8))
.max_lifetime(Duration::from_secs(60))
.sqlx_logging(false); .sqlx_logging(false);
// .sqlx_logging_level(log::LevelFilter::Info); // .sqlx_logging_level(log::LevelFilter::Info);