Merge pull request #1253 from TheBlueMatt/2022-01-background-persist-exit
[rust-lightning] / lightning-background-processor / src / lib.rs
index c3be857a3611f09490902386f1008b503f271b91..b60dc6c830432c47777faa4a7b84db9e666ba954 100644 (file)
@@ -238,7 +238,7 @@ impl BackgroundProcessor {
                                // Exit the loop if the background processor was requested to stop.
                                if stop_thread.load(Ordering::Acquire) == true {
                                        log_trace!(logger, "Terminating background processor.");
-                                       return Ok(());
+                                       break;
                                }
                                if last_freshness_call.elapsed().as_secs() > FRESHNESS_TIMER {
                                        log_trace!(logger, "Calling ChannelManager's timer_tick_occurred");
@@ -280,6 +280,10 @@ impl BackgroundProcessor {
                                        }
                                }
                        }
+                       // After we exit, ensure we persist the ChannelManager one final time - this avoids
+                       // some races where users quit while channel updates were in-flight, with
+                       // ChannelMonitor update(s) persisted without a corresponding ChannelManager update.
+                       persister.persist_manager(&*channel_manager)
                });
                Self { stop_thread: stop_thread_clone, thread_handle: Some(handle) }
        }