@@ -746,6 +746,7 @@ impl ApiState {
746
746
self . stop_progress ( instance_id) . await ;
747
747
loop {
748
748
let instances = self . instances . read ( ) . await ;
749
+ trace ! ( "grabbed instances in delete_instance; instance_id={}" , instance_id) ;
749
750
let mut instance = instances[ instance_id] . lock ( ) . await ;
750
751
match & instance. state {
751
752
InstanceState :: Available ( _) => {
@@ -759,15 +760,18 @@ impl ApiState {
759
760
}
760
761
drop ( instance) ;
761
762
drop ( instances) ;
763
+ trace ! ( "released instances in delete_instance; instance_id={}" , instance_id) ;
762
764
tokio:: time:: sleep ( Duration :: from_secs ( 1 ) ) . await ;
763
765
}
764
766
}
765
767
766
768
pub async fn delete_all_instances ( arc_self : Arc < ApiState > ) {
767
769
let mut tasks = JoinSet :: new ( ) ;
768
770
let instances = arc_self. instances . read ( ) . await ;
771
+ trace ! ( "delete_all_instances: grabbed instances" ) ;
769
772
let num_instances = instances. len ( ) ;
770
773
drop ( instances) ;
774
+ trace ! ( "delete_all_instances: released instances" ) ;
771
775
for instance_id in 0 ..num_instances {
772
776
let arc_self_clone = arc_self. clone ( ) ;
773
777
tasks. spawn ( async move { arc_self_clone. delete_instance ( instance_id) . await } ) ;
@@ -1169,6 +1173,7 @@ impl ApiState {
1169
1173
let request_id = canister_http_request. request_id ;
1170
1174
let response = loop {
1171
1175
let instances = instances. read ( ) . await ;
1176
+ trace ! ( "process_canister_http_requests: grabbed instances; instance_id={}" , instance_id) ;
1172
1177
let instance = instances[ instance_id] . lock ( ) . await ;
1173
1178
if let InstanceState :: Available ( pocket_ic) = & instance. state {
1174
1179
let canister_http_adapters = pocket_ic. canister_http_adapters ( ) ;
@@ -1193,6 +1198,7 @@ impl ApiState {
1193
1198
}
1194
1199
drop ( instance) ;
1195
1200
drop ( instances) ;
1201
+ trace ! ( "process_canister_http_requests: released instances; instance_id={}" , instance_id) ;
1196
1202
tokio:: time:: sleep ( Duration :: from_millis ( 10 ) ) . await ;
1197
1203
} ;
1198
1204
let mock_canister_http_response = MockCanisterHttpResponse {
@@ -1228,6 +1234,7 @@ impl ApiState {
1228
1234
let instances_clone = self . instances . clone ( ) ;
1229
1235
let graph = self . graph . clone ( ) ;
1230
1236
let instances = self . instances . read ( ) . await ;
1237
+ trace ! ( "auto_progress: grabbed instances; instance_id={}" , instance_id) ;
1231
1238
let mut instance = instances[ instance_id] . lock ( ) . await ;
1232
1239
if instance. progress_thread . is_none ( ) {
1233
1240
let ( tx, mut rx) = mpsc:: channel :: < ( ) > ( 1 ) ;
@@ -1272,26 +1279,32 @@ impl ApiState {
1272
1279
}
1273
1280
} ) ;
1274
1281
instance. progress_thread = Some ( ProgressThread { handle, sender : tx } ) ;
1282
+ trace ! ( "auto_progress: released instances; instance_id={}" , instance_id) ;
1275
1283
Ok ( ( ) )
1276
1284
} else {
1285
+ trace ! ( "auto_progress: released instances; instance_id={}" , instance_id) ;
1277
1286
Err ( "Auto progress mode has already been enabled." . to_string ( ) )
1278
1287
}
1279
1288
}
1280
1289
1281
1290
pub async fn stop_progress ( & self , instance_id : InstanceId ) {
1282
1291
let instances = self . instances . read ( ) . await ;
1292
+ trace ! ( "stop_progress: grabbed instances; instance_id={}" , instance_id) ;
1283
1293
let mut instance = instances[ instance_id] . lock ( ) . await ;
1284
1294
let progress_thread = instance. progress_thread . take ( ) ;
1285
1295
// drop locks otherwise we might end up with a deadlock
1286
1296
drop ( instance) ;
1287
1297
drop ( instances) ;
1298
+ trace ! ( "stop_progress: released instances; instance_id={}" , instance_id) ;
1299
+ let mut instance = instances[ instance_id] . lock ( ) . await ;
1288
1300
if let Some ( t) = progress_thread {
1289
1301
t. sender . send ( ( ) ) . await . unwrap ( ) ;
1290
1302
t. handle . await . unwrap ( ) ;
1291
1303
}
1292
1304
}
1293
1305
1294
1306
pub async fn list_instance_states ( & self ) -> Vec < String > {
1307
+ panic ! ( "" ) ;
1295
1308
let instances = self . instances . read ( ) . await ;
1296
1309
let mut res = vec ! [ ] ;
1297
1310
@@ -1386,6 +1399,8 @@ impl ApiState {
1386
1399
) ;
1387
1400
let instances_cloned = instances. clone ( ) ;
1388
1401
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 ;
1389
1404
let ( bg_task, busy_outcome) = if let Some ( instance_mutex) =
1390
1405
instances_locked. get ( instance_id)
1391
1406
{
@@ -1438,6 +1453,7 @@ impl ApiState {
1438
1453
// add result to graph, but grab instance lock first!
1439
1454
println ! ( "waiting to grab instane: old={:?} op_id={:?}" , old_state_label, op_id) ;
1440
1455
let instances = instances. blocking_read ( ) ;
1456
+ trace ! ( "update_instances_with_timeout-thread: grabbed instances; instance_id={}" , instance_id) ;
1441
1457
println ! ( "waiting to grab graph: old={:?} op_id={:?}" , old_state_label, op_id) ;
1442
1458
let mut graph_guard = graph. blocking_write ( ) ;
1443
1459
println ! ( "grabbed graph: old={:?} op_id={:?}" , old_state_label, op_id) ;
@@ -1455,6 +1471,7 @@ impl ApiState {
1455
1471
instance. state = InstanceState :: Available ( pocket_ic) ;
1456
1472
}
1457
1473
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) ;
1458
1475
result
1459
1476
}
1460
1477
} ;
@@ -1470,6 +1487,7 @@ impl ApiState {
1470
1487
} ;
1471
1488
// drop lock, otherwise we end up with a deadlock
1472
1489
std:: mem:: drop ( instances_locked) ;
1490
+ trace ! ( "update_instances_with_timeout: released instances; instance_id={}" , instance_id) ;
1473
1491
1474
1492
// We schedule a blocking background task on the tokio runtime. Note that if all
1475
1493
// blocking workers are busy, the task is put on a queue (which is what we want).
0 commit comments