From 025762f2fe86f85f503797c46374406cdaf5597a Mon Sep 17 00:00:00 2001 From: Meshiest Date: Mon, 25 Mar 2024 20:17:21 -0500 Subject: [PATCH] fix(cannon): fix reference cycle --- crates/snot/src/cannon/mod.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/crates/snot/src/cannon/mod.rs b/crates/snot/src/cannon/mod.rs index f9044152..6773b4d0 100644 --- a/crates/snot/src/cannon/mod.rs +++ b/crates/snot/src/cannon/mod.rs @@ -5,7 +5,7 @@ pub mod source; use std::{ collections::HashSet, - sync::{atomic::AtomicU32, Arc}, + sync::{atomic::AtomicU32, Arc, Weak}, }; use anyhow::{bail, Result}; @@ -63,7 +63,7 @@ pub struct CannonInstance { /// To point at an external node, create a topology with external node /// To generate ahead-of-time, upload a test with a timeline referencing a /// cannon pointing at a file - env: Arc, + env: Weak, /// Local query service port. Only present if the TxSource uses a local query source. query_port: Option, @@ -131,7 +131,7 @@ impl CannonInstance { global_state, source, sink, - env, + env: Arc::downgrade(&env), tx_sender, query_port, task: AsyncMutex::new(handle.abort_handle()), @@ -152,8 +152,12 @@ impl CannonInstance { } } LedgerQueryService::Node(key) => { + let Some(env) = self.env.upgrade() else { + unreachable!("called from a place where env is present") + }; + // env_id must be Some because LedgerQueryService::Node requires it - let Some(agent_id) = self.env.get_agent_by_key(key) else { + let Some(agent_id) = env.get_agent_by_key(key) else { bail!("cannon target agent not found") };