From 4ca1f661d59dfe5288debb37d1805b993b6d9185 Mon Sep 17 00:00:00 2001 From: Roderick van Domburg Date: Thu, 6 Jan 2022 09:43:50 +0100 Subject: [PATCH] Prevent deadlock --- core/src/apresolve.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/core/src/apresolve.rs b/core/src/apresolve.rs index 1e1c6de6..72b089dd 100644 --- a/core/src/apresolve.rs +++ b/core/src/apresolve.rs @@ -1,8 +1,3 @@ -use std::{ - hint, - sync::atomic::{AtomicBool, Ordering}, -}; - use hyper::{Body, Method, Request}; use serde::Deserialize; @@ -40,7 +35,6 @@ impl Default for ApResolveData { component! { ApResolver : ApResolverInner { data: AccessPoints = AccessPoints::default(), - in_progress: AtomicBool = AtomicBool::new(false), } } @@ -111,16 +105,6 @@ impl ApResolver { } pub async fn resolve(&self, endpoint: &str) -> Result { - // Use a spinlock to make this function atomic. Otherwise, various race conditions may - // occur, e.g. when the session is created, multiple components are launched almost in - // parallel and they will all call this function, while resolving is still in progress. - self.lock(|inner| { - while inner.in_progress.load(Ordering::Acquire) { - hint::spin_loop(); - } - inner.in_progress.store(true, Ordering::Release); - }); - if self.is_empty() { self.apresolve().await; } @@ -140,7 +124,7 @@ impl ApResolver { ))) } }; - inner.in_progress.store(false, Ordering::Release); + Ok(access_point) }) }