diff --git a/src/runtime2/component/consensus.rs b/src/runtime2/component/consensus.rs index d30f5874a04afb8df60b09bb39b3ad8f0c4f08e7..a0544a3d7f80b0db21a56e09d5c096e28ba89732 100644 --- a/src/runtime2/component/consensus.rs +++ b/src/runtime2/component/consensus.rs @@ -666,8 +666,13 @@ impl Consensus { fn send_to_leader(&mut self, sched_ctx: &SchedulerCtx, comp_ctx: &CompCtx, message: Message) { debug_assert_ne!(self.highest_id, comp_ctx.id); // we're not the leader - let leader_info = sched_ctx.runtime.get_component_public(self.highest_id); + let mut leader_info = sched_ctx.runtime.get_component_public(self.highest_id); leader_info.send_message(sched_ctx, message, true); + let should_remove = leader_info.decrement_users(); + if should_remove { + let key = unsafe{ self.highest_id.upgrade() }; + sched_ctx.runtime.destroy_component(key); + } } // -------------------------------------------------------------------------