fix shutdown
This commit is contained in:
parent
b1bbeb392b
commit
24bd401c90
@ -59,8 +59,10 @@ pub async fn run_veilid_server_internal(
|
|||||||
|
|
||||||
// Create VeilidCore setup
|
// Create VeilidCore setup
|
||||||
let update_callback = Arc::new(move |change: veilid_core::VeilidUpdate| {
|
let update_callback = Arc::new(move |change: veilid_core::VeilidUpdate| {
|
||||||
if sender.send(change).is_err() {
|
if let Err(e) = sender.send(change) {
|
||||||
error!("error sending veilid update callback");
|
// Don't log here, as that loops the update callback in some cases and will deadlock
|
||||||
|
let change = e.into_inner();
|
||||||
|
eprintln!("error sending veilid update callback: {:?}", change);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let config_callback = settings.get_core_config_callback();
|
let config_callback = settings.get_core_config_callback();
|
||||||
@ -88,12 +90,8 @@ pub async fn run_veilid_server_internal(
|
|||||||
|
|
||||||
// Process all updates
|
// Process all updates
|
||||||
let capi2 = capi.clone();
|
let capi2 = capi.clone();
|
||||||
let mut shutdown_switch = {
|
let update_receiver_shutdown = SingleShotEventual::new(Some(()));
|
||||||
let shutdown_switch_locked = SHUTDOWN_SWITCH.lock();
|
let mut update_receiver_shutdown_instance = update_receiver_shutdown.instance().fuse();
|
||||||
(*shutdown_switch_locked).as_ref().map(|ss| ss.instance())
|
|
||||||
}
|
|
||||||
.unwrap()
|
|
||||||
.fuse();
|
|
||||||
let update_receiver_jh = spawn_local(async move {
|
let update_receiver_jh = spawn_local(async move {
|
||||||
loop {
|
loop {
|
||||||
select! {
|
select! {
|
||||||
@ -107,7 +105,7 @@ pub async fn run_veilid_server_internal(
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ = shutdown_switch => {
|
_ = update_receiver_shutdown_instance => {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -177,6 +175,9 @@ pub async fn run_veilid_server_internal(
|
|||||||
// Shut down Veilid API to release state change sender
|
// Shut down Veilid API to release state change sender
|
||||||
veilid_api.shutdown().await;
|
veilid_api.shutdown().await;
|
||||||
|
|
||||||
|
// Shut down update receiver now that there are no more updates
|
||||||
|
update_receiver_shutdown.resolve(()).await;
|
||||||
|
|
||||||
// Wait for update receiver to exit
|
// Wait for update receiver to exit
|
||||||
let _ = update_receiver_jh.await;
|
let _ = update_receiver_jh.await;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user