instance: drop peer_mgr in time

This commit is contained in:
Luna Yao
2026-04-06 11:55:22 +02:00
parent 604386f7e2
commit 39c595b5e9
+17 -16
View File
@@ -776,10 +776,11 @@ impl Instance {
tokio::spawn(async move { tokio::spawn(async move {
let mut output_tx = Some(first_round_output); let mut output_tx = Some(first_round_output);
loop { loop {
let close_notifier = Arc::new(Notify::new()); let close_notifier = Arc::new(Notify::new());
{ let mut new_nic_ctx = {
let Some(peer_mgr) = peer_mgr.upgrade() else { let Some(peer_manager) = peer_mgr.upgrade() else {
tracing::warn!("peer manager is dropped, stop static ip check."); tracing::warn!("peer manager is dropped, stop static ip check.");
if let Some(output_tx) = output_tx.take() { if let Some(output_tx) = output_tx.take() {
let _ = output_tx.send(Err(Error::Unknown)); let _ = output_tx.send(Err(Error::Unknown));
@@ -788,26 +789,26 @@ impl Instance {
return; return;
}; };
let mut new_nic_ctx = NicCtx::new( NicCtx::new(
peer_mgr.get_global_ctx(), peer_manager.get_global_ctx(),
&peer_mgr, &peer_manager,
peer_packet_receiver.clone(), peer_packet_receiver.clone(),
close_notifier.clone(), close_notifier.clone(),
); )
};
if let Err(e) = new_nic_ctx.run(ipv4_addr, ipv6_addr).await { if let Err(e) = new_nic_ctx.run(ipv4_addr, ipv6_addr).await {
if let Some(output_tx) = output_tx.take() { if let Some(output_tx) = output_tx.take() {
let _ = output_tx.send(Err(e)); let _ = output_tx.send(Err(e));
return; return;
}
tracing::error!("failed to create new nic ctx, err: {:?}", e);
tokio::time::sleep(Duration::from_secs(1)).await;
continue;
} }
tracing::error!("failed to create new nic ctx, err: {:?}", e);
Self::use_new_nic_ctx(nic_ctx.clone(), new_nic_ctx).await; tokio::time::sleep(Duration::from_secs(1)).await;
continue;
} }
Self::use_new_nic_ctx(nic_ctx.clone(), new_nic_ctx).await;
if let Some(output_tx) = output_tx.take() { if let Some(output_tx) = output_tx.take() {
let _ = output_tx.send(Ok(())); let _ = output_tx.send(Ok(()));
} }