Skip to content

Commit

Permalink
ReconnectingConnection: Use sync mutex.
Browse files Browse the repository at this point in the history
Since the mutex is never held across an await point, there's no need for
an async mutex.
  • Loading branch information
shachlanAmazon committed Jul 24, 2023
1 parent eaaaed7 commit 2d52b7d
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions babushka-core/src/client/reconnecting_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -132,7 +132,7 @@ impl ReconnectingConnection {
}

pub(super) async fn try_get_connection(&self) -> Option<MultiplexedConnection> {
let guard = self.inner.state.lock().await;
let guard = self.inner.state.lock().unwrap();
if let ConnectionState::Connected(connection) = &*guard {
Some(connection.clone())
} else {
Expand All @@ -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();
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 2d52b7d

Please sign in to comment.