Skip to content

Commit

Permalink
Prevent memory leak from build up of timer jobs
Browse files Browse the repository at this point in the history
  • Loading branch information
hpeebles committed Aug 2, 2024
1 parent a6a8c38 commit 04eb371
Showing 1 changed file with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,9 @@ async fn run_async() {

let mut neurons_updated = false;
if !neurons_to_spawn.is_empty() {
spawn_neurons(neurons_to_spawn).await;
neurons_updated = true;
if spawn_neurons(neurons_to_spawn).await {
neurons_updated = true;
}
}

if !neurons_to_disburse.is_empty() {
Expand All @@ -90,12 +91,12 @@ async fn run_async() {

if neurons_updated {
// Refresh the neurons again given that they've been updated
ic_cdk_timers::set_timer(Duration::ZERO, || ic_cdk::spawn(run_async()));
ic_cdk_timers::set_timer(Duration::ZERO, run);
}
}
}

async fn spawn_neurons(neuron_ids: Vec<u64>) {
async fn spawn_neurons(neuron_ids: Vec<u64>) -> bool {
let (nns_ledger_canister_id, cycles_minting_canister_id, cycles_dispenser_canister_id) = read_state(|state| {
(
state.data.nns_ledger_canister_id,
Expand All @@ -118,6 +119,9 @@ async fn spawn_neurons(neuron_ids: Vec<u64>) {
info!(neuron_id, "Spawning neuron from maturity");
manage_nns_neuron_impl(neuron_id, Command::Spawn(Spawn::default())).await;
}
true
} else {
false
}
}

Expand Down

0 comments on commit 04eb371

Please sign in to comment.