From ac17b11e09115947e7cf76d66d3ad35c59b47258 Mon Sep 17 00:00:00 2001 From: Sanchith Hegde <22217505+SanchithHegde@users.noreply.github.com> Date: Tue, 25 Jul 2023 15:15:33 +0530 Subject: [PATCH] refactor(redis_interface): remove the `Drop` implementation on `RedisConnectionPool` (#1786) --- crates/redis_interface/src/lib.rs | 35 ------------------------------- crates/router/src/connection.rs | 1 - 2 files changed, 36 deletions(-) diff --git a/crates/redis_interface/src/lib.rs b/crates/redis_interface/src/lib.rs index b06cc6c274..3df54d5dc8 100644 --- a/crates/redis_interface/src/lib.rs +++ b/crates/redis_interface/src/lib.rs @@ -33,7 +33,6 @@ pub use self::{commands::*, types::*}; pub struct RedisConnectionPool { pub pool: fred::pool::RedisPool, config: RedisConfig, - join_handles: Vec, pub subscriber: SubscriberClient, pub publisher: RedisClient, pub is_redis_available: Arc, @@ -136,7 +135,6 @@ impl RedisConnectionPool { .into_report() .change_context(errors::RedisError::RedisConnectionError)?; - let join_handles = pool.connect(); pool.wait_for_connect() .await .into_report() @@ -147,37 +145,12 @@ impl RedisConnectionPool { Ok(Self { pool, config, - join_handles, is_redis_available: Arc::new(atomic::AtomicBool::new(true)), subscriber, publisher, }) } - pub async fn close_connections(&mut self) { - self.pool.quit_pool().await; - - self.publisher - .quit() - .await - .map_err(|err| logger::error!(redis_quit_err=?err)) - .ok(); - - self.subscriber - .quit() - .await - .map_err(|err| logger::error!(redis_quit_err=?err)) - .ok(); - - for handle in self.join_handles.drain(..) { - match handle.await { - Ok(Ok(_)) => (), - Ok(Err(error)) => logger::error!(%error), - Err(error) => logger::error!(%error), - }; - } - } - pub async fn on_error(&self, tx: tokio::sync::oneshot::Sender<()>) { while let Ok(redis_error) = self.pool.on_error().recv().await { logger::error!(?redis_error, "Redis protocol or connection error"); @@ -194,14 +167,6 @@ impl RedisConnectionPool { } } -impl Drop for RedisConnectionPool { - // safety: panics when invoked without a current tokio runtime - fn drop(&mut self) { - let rt = tokio::runtime::Handle::current(); - rt.block_on(self.close_connections()) - } -} - struct RedisConfig { default_ttl: u32, default_stream_read_count: u64, diff --git a/crates/router/src/connection.rs b/crates/router/src/connection.rs index a84039a903..a5d436d0d8 100644 --- a/crates/router/src/connection.rs +++ b/crates/router/src/connection.rs @@ -10,7 +10,6 @@ use crate::{configs::settings::Database, errors}; pub type PgPool = bb8::Pool>; pub type PgPooledConn = async_bb8_diesel::Connection; -pub type RedisPool = std::sync::Arc; #[derive(Debug)] struct TestTransaction;