From 4719b93ce553c6883ea87d4bc6478e479f1fd5c5 Mon Sep 17 00:00:00 2001 From: ModulatingForce <116608425+modulatingforce@users.noreply.github.com> Date: Sat, 30 Mar 2024 19:25:07 -0400 Subject: [PATCH] addl debug --- src/core/bot_actions.rs | 45 ++++++++++++++++++++---- src/core/botmodules.rs | 35 +++++++++++++++--- src/custom/experimental/experiment003.rs | 4 +-- 3 files changed, 72 insertions(+), 12 deletions(-) diff --git a/src/core/bot_actions.rs b/src/core/bot_actions.rs index 37f2445..fae3d3b 100644 --- a/src/core/bot_actions.rs +++ b/src/core/bot_actions.rs @@ -52,10 +52,33 @@ impl ExecBodyParams { pub async fn get_channel(&self) -> Option { + dbg!("Core > ExecBodyParams > GetChannels START"); + dbg!("!! [x] Document - After SUCCESS message was sent to chat"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1 "); + dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0 "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2"); + let curr_act = Arc::clone(&self.curr_act); - let parent_act_lock = curr_act.read().await; - let act = &(*parent_act_lock); + let curr_act_lock = curr_act.read().await; + + dbg!("Core > ExecBodyParams > After Creating ExecBodyParams.current_act.read() Guard "); + dbg!("!! [x] Document - After SUCCESS message was sent to chat"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1 "); + dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0 "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2"); + + let act = &(*curr_act_lock); + + dbg!("Core > ExecBodyParams > Using the Read Guard "); + dbg!("!! [x] Document - After SUCCESS message was sent to chat"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = Not Listed "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2"); + let out = match act { BotAction::C(_) => { // let temp = c.module.clone(); @@ -72,12 +95,22 @@ impl ExecBodyParams { // let temp = r.module.clone(); // Some(temp) dbg!("Core > ExecBodyParams > GetChannels - routine identified"); - dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 1 "); - dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + dbg!("!! [x] Document"); + dbg!(">> BotActionAR - RwLock from botmodules.rs::930:46 - current_readers = 2"); + dbg!(">> RoutineAR - RwLock from botmodules.rs::1262:32 - current_readers = 1"); dbg!(">> join_handle - RwLock from botmodules.rs::1226:46 - current_readers = 0"); - dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 3 "); + dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 1"); // => 03.30 - Just before deadlock - let out = Some(r.read().await.channel.clone()); + // dbg!("ISSUE : RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + // let out = Some(r.read().await.channel.clone()); + + let guard = r.read().await; + + dbg!("ISSUE> Never makes it after the read guard"); + + let channel = guard.channel.clone(); + drop(guard); + let out = Some(channel); // => 03.30 - This isn't reached because of the Deadlock dbg!(">> Just after Potential Deadlock Lock"); diff --git a/src/core/botmodules.rs b/src/core/botmodules.rs index 65d902a..5a45979 100644 --- a/src/core/botmodules.rs +++ b/src/core/botmodules.rs @@ -507,6 +507,7 @@ pub struct BotCommand { impl BotCommand { pub async fn execute(&self, params : ExecBodyParams) { + // This is how BotCommand implements their Working exec_body (*self.exec_body)(params).await; } } @@ -643,7 +644,7 @@ pub struct Routine { pub name : String , pub module : BotModule , // from() can determine this if passed parents_params pub channel : Channel , // Requiring some channel context - exec_body: bot_actions::actions_util::ExecBody, + exec_body: Arc>, pub parent_params : ExecBodyParams , pub join_handle : Option>>> , start_time : Option> , @@ -895,7 +896,7 @@ impl Routine { module : BotModule , channel : Channel, routine_attr : Vec , - exec_body : bot_actions::actions_util::ExecBody , + exec_body : Arc> , parent_params : ExecBodyParams ) -> Result< Arc>, @@ -1285,17 +1286,43 @@ impl Routine { parent_params }; - dbg!("Core > Guarding & Executing Child Execution Body"); + dbg!("Core > Guarding and will Execute Child Execution Body"); dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 0 "); dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = Not Listed"); dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 3 "); + // { + // // The below starts the Read Lock that conlicts + // let guard2 = self_ar.read().await; + + // dbg!("Core > Guarded & Executing Child Execution Body"); + // dbg!("!! [x] Document "); + // dbg!(">> BotActionAR - RwLock from botmodules.rs::929:46 - current_readers = 0 "); + // dbg!(">> RoutineAR - RwLock from botmodules.rs::1261:32 - current_readers = 1"); + // dbg!(">> BotInstanceAR - RwLock from botinstance.rs::150:28 - current_readers = 2 "); + // // this way seems to be having issues for Routine > Loopbody + // // in particular, because by this point we have a ReadGuard on Routine + // // somehow the read guard is conflicting with a read guard in the underlying + // // fn? + // (guard2.exec_body)(parent_params).await; + // drop(guard2); + + // } + { + let guard2 = self_ar.read().await; - (guard2.exec_body)(parent_params).await; + let exec_body_ar = guard2.exec_body.clone(); drop(guard2); + let guard3 = exec_body_ar.read().await; + (guard3)(parent_params).await; + drop(guard3); + } + + + // (self_ar.read().await.exec_body)( // parent_params // ).await; diff --git a/src/custom/experimental/experiment003.rs b/src/custom/experimental/experiment003.rs index fdcdde6..0be50a3 100644 --- a/src/custom/experimental/experiment003.rs +++ b/src/custom/experimental/experiment003.rs @@ -279,7 +279,7 @@ async fn countdown_chnl_v1(params : ExecBodyParams) { module, channel.unwrap(), routine_attr, - exec_body, + Arc::new(RwLock::new(exec_body)), params.clone() ).await { let newr_ar = newr.clone(); @@ -475,7 +475,7 @@ async fn test3_body(params : ExecBodyParams) { module, channel.unwrap(), routine_attr, - exec_body, + Arc::new(RwLock::new(exec_body)), params.clone() ).await;