Skip to content

Commit 93fd6fe

Browse files
committed
dbg
1 parent a0a059b commit 93fd6fe

File tree

1 file changed

+18
-0
lines changed
  • rs/pocket_ic_server/src/state_api

1 file changed

+18
-0
lines changed

rs/pocket_ic_server/src/state_api/state.rs

+18
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,7 @@ impl ApiState {
746746
self.stop_progress(instance_id).await;
747747
loop {
748748
let instances = self.instances.read().await;
749+
trace!("grabbed instances in delete_instance; instance_id={}", instance_id);
749750
let mut instance = instances[instance_id].lock().await;
750751
match &instance.state {
751752
InstanceState::Available(_) => {
@@ -759,15 +760,18 @@ impl ApiState {
759760
}
760761
drop(instance);
761762
drop(instances);
763+
trace!("released instances in delete_instance; instance_id={}", instance_id);
762764
tokio::time::sleep(Duration::from_secs(1)).await;
763765
}
764766
}
765767

766768
pub async fn delete_all_instances(arc_self: Arc<ApiState>) {
767769
let mut tasks = JoinSet::new();
768770
let instances = arc_self.instances.read().await;
771+
trace!("delete_all_instances: grabbed instances");
769772
let num_instances = instances.len();
770773
drop(instances);
774+
trace!("delete_all_instances: released instances");
771775
for instance_id in 0..num_instances {
772776
let arc_self_clone = arc_self.clone();
773777
tasks.spawn(async move { arc_self_clone.delete_instance(instance_id).await });
@@ -1169,6 +1173,7 @@ impl ApiState {
11691173
let request_id = canister_http_request.request_id;
11701174
let response = loop {
11711175
let instances = instances.read().await;
1176+
trace!("process_canister_http_requests: grabbed instances; instance_id={}", instance_id);
11721177
let instance = instances[instance_id].lock().await;
11731178
if let InstanceState::Available(pocket_ic) = &instance.state {
11741179
let canister_http_adapters = pocket_ic.canister_http_adapters();
@@ -1193,6 +1198,7 @@ impl ApiState {
11931198
}
11941199
drop(instance);
11951200
drop(instances);
1201+
trace!("process_canister_http_requests: released instances; instance_id={}", instance_id);
11961202
tokio::time::sleep(Duration::from_millis(10)).await;
11971203
};
11981204
let mock_canister_http_response = MockCanisterHttpResponse {
@@ -1228,6 +1234,7 @@ impl ApiState {
12281234
let instances_clone = self.instances.clone();
12291235
let graph = self.graph.clone();
12301236
let instances = self.instances.read().await;
1237+
trace!("auto_progress: grabbed instances; instance_id={}", instance_id);
12311238
let mut instance = instances[instance_id].lock().await;
12321239
if instance.progress_thread.is_none() {
12331240
let (tx, mut rx) = mpsc::channel::<()>(1);
@@ -1272,26 +1279,32 @@ impl ApiState {
12721279
}
12731280
});
12741281
instance.progress_thread = Some(ProgressThread { handle, sender: tx });
1282+
trace!("auto_progress: released instances; instance_id={}", instance_id);
12751283
Ok(())
12761284
} else {
1285+
trace!("auto_progress: released instances; instance_id={}", instance_id);
12771286
Err("Auto progress mode has already been enabled.".to_string())
12781287
}
12791288
}
12801289

12811290
pub async fn stop_progress(&self, instance_id: InstanceId) {
12821291
let instances = self.instances.read().await;
1292+
trace!("stop_progress: grabbed instances; instance_id={}", instance_id);
12831293
let mut instance = instances[instance_id].lock().await;
12841294
let progress_thread = instance.progress_thread.take();
12851295
// drop locks otherwise we might end up with a deadlock
12861296
drop(instance);
12871297
drop(instances);
1298+
trace!("stop_progress: released instances; instance_id={}", instance_id);
1299+
let mut instance = instances[instance_id].lock().await;
12881300
if let Some(t) = progress_thread {
12891301
t.sender.send(()).await.unwrap();
12901302
t.handle.await.unwrap();
12911303
}
12921304
}
12931305

12941306
pub async fn list_instance_states(&self) -> Vec<String> {
1307+
panic!("");
12951308
let instances = self.instances.read().await;
12961309
let mut res = vec![];
12971310

@@ -1386,6 +1399,8 @@ impl ApiState {
13861399
);
13871400
let instances_cloned = instances.clone();
13881401
let instances_locked = instances_cloned.read().await;
1402+
trace!("update_instances_with_timeout: grabbed instances; instance_id={}", instance_id);
1403+
let mut instance = instances[instance_id].lock().await;
13891404
let (bg_task, busy_outcome) = if let Some(instance_mutex) =
13901405
instances_locked.get(instance_id)
13911406
{
@@ -1438,6 +1453,7 @@ impl ApiState {
14381453
// add result to graph, but grab instance lock first!
14391454
println!("waiting to grab instane: old={:?} op_id={:?}", old_state_label, op_id);
14401455
let instances = instances.blocking_read();
1456+
trace!("update_instances_with_timeout-thread: grabbed instances; instance_id={}", instance_id);
14411457
println!("waiting to grab graph: old={:?} op_id={:?}", old_state_label, op_id);
14421458
let mut graph_guard = graph.blocking_write();
14431459
println!("grabbed graph: old={:?} op_id={:?}", old_state_label, op_id);
@@ -1455,6 +1471,7 @@ impl ApiState {
14551471
instance.state = InstanceState::Available(pocket_ic);
14561472
}
14571473
trace!("bg_task::end instance_id={} op_id={}", instance_id, op_id.0);
1474+
trace!("update_instances_with_timeout-thread: released instances; instance_id={}", instance_id);
14581475
result
14591476
}
14601477
};
@@ -1470,6 +1487,7 @@ impl ApiState {
14701487
};
14711488
// drop lock, otherwise we end up with a deadlock
14721489
std::mem::drop(instances_locked);
1490+
trace!("update_instances_with_timeout: released instances; instance_id={}", instance_id);
14731491

14741492
// We schedule a blocking background task on the tokio runtime. Note that if all
14751493
// blocking workers are busy, the task is put on a queue (which is what we want).

0 commit comments

Comments
 (0)