]> git.bitcoin.ninja Git - rust-lightning/commitdiff
Persist `ChannelManager` before `BackgroundProcessor` exits 2022-01-background-persist-exit
authorMatt Corallo <git@bluematt.me>
Tue, 18 Jan 2022 21:48:28 +0000 (21:48 +0000)
committerMatt Corallo <git@bluematt.me>
Tue, 18 Jan 2022 22:07:15 +0000 (22:07 +0000)
Fixes #1237.

lightning-background-processor/src/lib.rs

index 2dbc8053b4eb1247e5d64dc482e1817ad5db08ec..8f6ed657b3d8e116b5913ebb9b75e4dbdc218e41 100644 (file)
@@ -232,7 +232,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");
@@ -269,6 +269,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) }
        }