Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect if the background processor exits early and shutdown if so #109

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -802,7 +802,7 @@ async fn start_ldk() {

// Step 20: Background Processing
let (bp_exit, bp_exit_check) = tokio::sync::watch::channel(());
let background_processor = tokio::spawn(process_events_async(
let mut background_processor = tokio::spawn(process_events_async(
Arc::clone(&persister),
event_handler,
chain_monitor.clone(),
Expand Down Expand Up @@ -898,7 +898,7 @@ async fn start_ldk() {
));

// Start the CLI.
cli::poll_for_user_input(
let cli_poll = tokio::spawn(cli::poll_for_user_input(
Arc::clone(&peer_manager),
Arc::clone(&channel_manager),
Arc::clone(&keys_manager),
Expand All @@ -910,17 +910,29 @@ async fn start_ldk() {
network,
Arc::clone(&logger),
Arc::clone(&persister),
)
.await;
));

// Exit if either CLI polling exits or the background processor exits (which shouldn't happen
// unless we fail to write to the filesystem).
tokio::select! {
_ = cli_poll => {},
bg_res = &mut background_processor => {
stop_listen_connect.store(true, Ordering::Release);
peer_manager.disconnect_all_peers();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should do a last-ditch ChannelManager persist attempt before panicking.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

panic!("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.
stop_listen_connect.store(true, Ordering::Release);
peer_manager.disconnect_all_peers();

// Stop the background processor.
bp_exit.send(()).unwrap();
background_processor.await.unwrap().unwrap();
valentinewallace marked this conversation as resolved.
Show resolved Hide resolved
if !bp_exit.is_closed() {
bp_exit.send(()).unwrap();
background_processor.await.unwrap().unwrap();
}
}

#[tokio::main]
Expand Down