Skip to content

Commit

Permalink
Detect if the background processor exits early and shutdown if so
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinewallace committed Aug 3, 2023
1 parent b7daadc commit bbac222
Showing 1 changed file with 20 additions and 16 deletions.
36 changes: 20 additions & 16 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,21 +897,26 @@ async fn start_ldk() {
Arc::clone(&channel_manager),
));

// Start the CLI.
cli::poll_for_user_input(
Arc::clone(&peer_manager),
Arc::clone(&channel_manager),
Arc::clone(&keys_manager),
Arc::clone(&network_graph),
Arc::clone(&onion_messenger),
inbound_payments,
outbound_payments,
ldk_data_dir,
network,
Arc::clone(&logger),
Arc::clone(&persister),
)
.await;
// Exit if CLI polling exits or the background processor exits (which shouldn't happen unless we
// fail to write to the filesystem).
tokio::select! {
_ = cli::poll_for_user_input(
Arc::clone(&peer_manager),
Arc::clone(&channel_manager),
Arc::clone(&keys_manager),
Arc::clone(&network_graph),
Arc::clone(&onion_messenger),
inbound_payments,
outbound_payments,
ldk_data_dir,
network,
Arc::clone(&logger),
Arc::clone(&persister),
) => {},
bg_res = background_processor => {
println!("ERR: background processing stopped with result {:?}, exiting", bg_res);
},
}

// Disconnect our peers and stop accepting new connections. This ensures we don't continue
// updating our channel data after we've stopped the background processor.
Expand All @@ -920,7 +925,6 @@ async fn start_ldk() {

// Stop the background processor.
bp_exit.send(()).unwrap();
background_processor.await.unwrap().unwrap();
}

#[tokio::main]
Expand Down

0 comments on commit bbac222

Please sign in to comment.