From 31354f74ef7bc5d2147c9520d64c0601e25b588a Mon Sep 17 00:00:00 2001 From: Paul Campbell Date: Wed, 25 Dec 2024 19:17:59 +0000 Subject: [PATCH] fix(net): prevent race to match mocked net requests --- src/net/system.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/net/system.rs b/src/net/system.rs index fec2dfa..448bfb2 100644 --- a/src/net/system.rs +++ b/src/net/system.rs @@ -62,7 +62,7 @@ impl Plan { }, ), }); - tracing::debug!(?is_match); + tracing::debug!(?is_match, plan = ?self); is_match } } @@ -140,16 +140,15 @@ impl Net { }; tracing::debug!("build request"); let request = request.build()?; - let index = plans - .lock() - .await + let locked_plans = plans.lock().await; + let index = locked_plans .deref() .borrow() .iter() .position(|plan| plan.matches(&request)); match index { Some(i) => { - let plan = plans.lock().await.borrow_mut().remove(i); + let plan = locked_plans.borrow_mut().remove(i); let response = plan.response; if response.status().is_success() { tracing::debug!(?request, "matched success response");