From b5e95668a514fd7e59190b5d161a1cb346947848 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Fri, 29 Mar 2024 09:03:16 -0400 Subject: [PATCH] ISSUE - potential lock issue --- src/core/botmodules.rs | 4 +- src/custom/experimental/experiment003.rs | 127 +++++++++++++++-------- 2 files changed, 87 insertions(+), 44 deletions(-) diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 2cfbb77..f4dfb18 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -1104,7 +1104,9 @@ impl Routine { // [x] execution body // trg_routine_ar.read().await.loopbody().await; - trg_routine_ar.write().await.loopbody().await; + { + trg_routine_ar.write().await.loopbody().await; + } { // [x] End of Loop iteration diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index a37066f..41c1d65 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -152,34 +152,44 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { async fn innertester(params : ExecBodyParams) { - + { + let curract_guard = params.curr_act.read().await; + - let logmsg_botact = match *params.curr_act.read().await { - BotAction::C(_) => "command", - BotAction::R(_) => "routine", - BotAction::L(_) => "listener", - } ; + // let logmsg_botact = match *params.curr_act.read().await { + + let logmsg_botact = match *curract_guard { + BotAction::C(_) => "command", + BotAction::R(_) => "routine", + BotAction::L(_) => "listener", + } ; - botlog::trace( - format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), - Some("Experiments003 > countdown_chnl()".to_string()), - Some(¶ms.msg), - ); - Log::flush(); - - let bot = Arc::clone(¶ms.bot); - - let botlock = bot.read().await; - - if let BotAction::R(arr) = &*params.curr_act.read().await { - botlog::trace( - "Before loading remaining iterations", + format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), Some("Experiments003 > countdown_chnl()".to_string()), - None, + Some(¶ms.msg), ); Log::flush(); + } + + { + let bot = Arc::clone(¶ms.bot); + let botlock = bot.read().await; + + let curract_guard = params.curr_act.write().await; + + // let routine_lock = arr.write().await; + + if let BotAction::R(arr) = &*curract_guard { + // if let BotAction::R(arr) = &*params.curr_act.read().await { + + botlog::trace( + "Before loading remaining iterations", + Some("Experiments003 > countdown_chnl()".to_string()), + None, + ); + Log::flush(); // let iterleft = arr.read().await.remaining_iterations.unwrap_or(0); @@ -197,10 +207,10 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // } { - let routine_lock = arr.write().await; - let a = routine_lock.remaining_iterations; - println!("remaining iterations : {:?}", a); -} + let routine_lock = arr.write().await; + let a = routine_lock.remaining_iterations; + println!("remaining iterations : {:?}", a); + } botlog::trace( "after loading remaining iterations", @@ -251,9 +261,12 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { // chosen_channel.0.clone(), // outmsg, // params.clone() + + // ).await; } + } } @@ -361,27 +374,55 @@ async fn test3_body(params : ExecBodyParams) { async fn rtestbody(params : ExecBodyParams) { - let logmsg_botact = match *params.curr_act.read().await { - BotAction::C(_) => "command", - BotAction::R(_) => "routine", - BotAction::L(_) => "listener", - } ; + let guard = params.curr_act.read().await; + { + let logmsg_botact = match *guard { + BotAction::C(_) => "command", + BotAction::R(_) => "routine", + BotAction::L(_) => "listener", + } ; - botlog::trace( - format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), - Some("Experiments003 > test3 command body".to_string()), - Some(¶ms.msg), - ); - Log::flush(); + botlog::trace( + format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), + Some("Experiments003 > test3 command body".to_string()), + Some(¶ms.msg), + ); + Log::flush(); + } - if let BotAction::R(arr) = &*params.curr_act.read().await { - for curriter in 0..5 { - println!("tester - Routine - Completed Iterations : {}", - arr.read().await.complete_iterations); - println!("tester - Custom Loop - Completed Iterations : {}", - curriter); - sleep(Duration::from_secs_f64(0.5)).await; + + { + let logmsg_botact = match *guard { + BotAction::C(_) => "command 2", + BotAction::R(_) => "routine 2", + BotAction::L(_) => "listener 2", + } ; + + botlog::trace( + format!("Params > Curr_act type : {:?}", logmsg_botact).as_str(), + Some("Experiments003 > test3 command body".to_string()), + Some(¶ms.msg), + ); + Log::flush(); + } + + + { + println!("Critical code area start"); // <= 03.29 - This is printed + if let BotAction::R(c) = &*guard { + println!("{:?}",c.read().await.channel); } + println!("Critical code area end"); // <= 03.29 - ISSUE This is NOT printed + + // if let BotAction::R(arr) = &*params.curr_act.read().await { + // for curriter in 0..5 { + // println!("tester - Routine - Completed Iterations : {}", + // arr.read().await.complete_iterations); + // println!("tester - Custom Loop - Completed Iterations : {}", + // curriter); + // sleep(Duration::from_secs_f64(0.5)).await; + // } + // } } }