@@ -959,12 +959,11 @@ async fn start_ldk() {
959
959
960
960
// Exit if either CLI polling exits or the background processor exits (which shouldn't happen
961
961
// unless we fail to write to the filesystem).
962
+ let mut bg_res = Ok ( Ok ( ( ) ) ) ;
962
963
tokio:: select! {
963
964
_ = cli_poll => { } ,
964
- bg_res = & mut background_processor => {
965
- stop_listen_connect. store( true , Ordering :: Release ) ;
966
- peer_manager. disconnect_all_peers( ) ;
967
- panic!( "ERR: background processing stopped with result {:?}, exiting" , bg_res) ;
965
+ bg_exit = & mut background_processor => {
966
+ bg_res = bg_exit;
968
967
} ,
969
968
}
970
969
@@ -973,6 +972,21 @@ async fn start_ldk() {
973
972
stop_listen_connect. store ( true , Ordering :: Release ) ;
974
973
peer_manager. disconnect_all_peers ( ) ;
975
974
975
+ if let Err ( e) = bg_res {
976
+ let persist_res = persister. persist ( "manager" , & * channel_manager) . unwrap ( ) ;
977
+ use lightning:: util:: logger:: Logger ;
978
+ lightning:: log_error!(
979
+ & * logger,
980
+ "Last-ditch ChannelManager persistence result: {:?}" ,
981
+ persist_res
982
+ ) ;
983
+ panic ! (
984
+ "ERR: background processing stopped with result {:?}, exiting.\n \
985
+ Last-ditch ChannelManager persistence result {:?}",
986
+ e, persist_res
987
+ ) ;
988
+ }
989
+
976
990
// Stop the background processor.
977
991
if !bp_exit. is_closed ( ) {
978
992
bp_exit. send ( ( ) ) . unwrap ( ) ;
0 commit comments