Skip to content

Commit a7d2b6a

Browse files
committed
Fix circular Arc reference in HRN resolver action
In added logic to use the HRN resolver from `bitcoin-payment-instructions`, we created a circular `Arc` reference - the `LDKOnionMessageDNSSECHrnResolver` is used as a handler for the `OnionMessenger` but we also set a post-queue-action which holds a reference to the `PeerManager`. As a result, after our `Node` instance is `stop`ped and the `Node` `drop`ped, much of the node's memory will stick around, including the `NetworkGraph`. Here we fix this issue by using `Weak` pointers.
1 parent d8e33c1 commit a7d2b6a

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/builder.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,10 +1597,11 @@ fn build_with_store_internal(
15971597
Arc::clone(&keys_manager),
15981598
));
15991599

1600-
let peer_manager_clone = Arc::clone(&peer_manager);
1601-
1600+
let peer_manager_clone = Arc::downgrade(&peer_manager);
16021601
hrn_resolver.register_post_queue_action(Box::new(move || {
1603-
peer_manager_clone.process_events();
1602+
if let Some(upgraded_pointer) = peer_manager_clone.upgrade() {
1603+
upgraded_pointer.process_events();
1604+
}
16041605
}));
16051606

16061607
liquidity_source.as_ref().map(|l| l.set_peer_manager(Arc::downgrade(&peer_manager)));

0 commit comments

Comments
 (0)