From 8499b3f9d1c2ae013b2990b172ec91fd234e9699 Mon Sep 17 00:00:00 2001 From: Dessalines Date: Sun, 24 Nov 2019 12:29:49 -0800 Subject: [PATCH] Using mutex. --- server/service/src/main.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/server/service/src/main.rs b/server/service/src/main.rs index fc2486c..6d76067 100644 --- a/server/service/src/main.rs +++ b/server/service/src/main.rs @@ -28,7 +28,7 @@ const RATE_LIMIT_PER_SECOND: i32 = 60; pub struct State { rate_limits: Mutex>, - pool: r2d2::Pool, + pool: Mutex>, } #[derive(Debug)] @@ -45,7 +45,7 @@ fn main() { let shared_data = web::Data::new(State { rate_limits: Mutex::new(HashMap::new()), - pool: pool, + pool: Mutex::new(pool), }); HttpServer::new(move || { @@ -106,7 +106,7 @@ fn search( .body(format!("{{\"error\": \"{}\"}}", "Empty query".to_string())); } - let conn = data.pool.get().unwrap(); + let conn = data.pool.lock().unwrap().get().unwrap(); match check_rate_limit_full(data, &ip, RATE_LIMIT, RATE_LIMIT_PER_SECOND) { Ok(_) => HttpResponse::Ok()