From 2d52b7df86c1a109cb733ea4a7cfa21761dff016 Mon Sep 17 00:00:00 2001 From: Shachar Langbeheim Date: Mon, 24 Jul 2023 15:36:02 +0000 Subject: [PATCH] ReconnectingConnection: Use sync mutex. Since the mutex is never held across an await point, there's no need for an async mutex. --- babushka-core/src/client/reconnecting_connection.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/babushka-core/src/client/reconnecting_connection.rs b/babushka-core/src/client/reconnecting_connection.rs index 6a0bcb711d..6095a8ec2e 100644 --- a/babushka-core/src/client/reconnecting_connection.rs +++ b/babushka-core/src/client/reconnecting_connection.rs @@ -6,8 +6,8 @@ use redis::aio::{ConnectionLike, MultiplexedConnection}; use redis::{RedisConnectionInfo, RedisError, RedisResult}; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::Arc; +use std::sync::Mutex; use std::time::Duration; -use tokio::sync::Mutex; use tokio::task; use tokio_retry::Retry; @@ -132,7 +132,7 @@ impl ReconnectingConnection { } pub(super) async fn try_get_connection(&self) -> Option { - let guard = self.inner.state.lock().await; + let guard = self.inner.state.lock().unwrap(); if let ConnectionState::Connected(connection) = &*guard { Some(connection.clone()) } else { @@ -151,7 +151,7 @@ impl ReconnectingConnection { pub(super) async fn reconnect(&self) { { - let mut guard = self.inner.state.lock().await; + let mut guard = self.inner.state.lock().unwrap(); match &*guard { ConnectionState::Connected(_) => { self.inner.backend.connection_available_signal.reset(); @@ -183,7 +183,7 @@ impl ReconnectingConnection { match get_multiplexed_connection(client).await { Ok(connection) => { { - let mut guard = connection_clone.inner.state.lock().await; + let mut guard = connection_clone.inner.state.lock().unwrap(); log_debug("reconnect", "completed succesfully"); connection_clone .inner @@ -201,7 +201,7 @@ impl ReconnectingConnection { } pub(super) fn get_db(&self) -> i64 { - let guard = self.inner.state.blocking_lock(); + let guard = self.inner.state.lock().unwrap(); match &*guard { ConnectionState::Connected(connection) => connection.get_db(), _ => -1,