refactor(redis_interface): remove the Drop implementation on RedisConnectionPool (#1786)

This commit is contained in:
Sanchith Hegde
2023-07-25 15:15:33 +05:30
committed by GitHub
parent 435c939576
commit ac17b11e09
2 changed files with 0 additions and 36 deletions

View File

@ -33,7 +33,6 @@ pub use self::{commands::*, types::*};
pub struct RedisConnectionPool {
pub pool: fred::pool::RedisPool,
config: RedisConfig,
join_handles: Vec<fred::types::ConnectHandle>,
pub subscriber: SubscriberClient,
pub publisher: RedisClient,
pub is_redis_available: Arc<atomic::AtomicBool>,
@ -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,

View File

@ -10,7 +10,6 @@ use crate::{configs::settings::Database, errors};
pub type PgPool = bb8::Pool<async_bb8_diesel::ConnectionManager<PgConnection>>;
pub type PgPooledConn = async_bb8_diesel::Connection<PgConnection>;
pub type RedisPool = std::sync::Arc<redis_interface::RedisConnectionPool>;
#[derive(Debug)]
struct TestTransaction;